静态资源服务器例子
发布于 19天前 作者 VectorHo 146 次浏览 来自 分享
var express = require('express');
var send = require('send');
var _ = require('underscore');
var path = require("path");
module.exports = app = express();
// hack!! 响应任何层级请求类型,send模块智能判断content-type
app.get('/:path/[^\s]*', function(req, res, next) {
  var resource = '/' + _.drop(_.compact(req.path.split('/')), 1).join('/');
  console.log(resource);
  send(req, resource, {root: path.resolve(__dirname, req.params.path)}).pipe(res);
});
app.listen(process.env.PORT || 3000);
console.log("Test Listen on port 3000");
回到顶部