Skip to content

Instantly share code, notes, and snippets.

@getchenge
Created June 29, 2014 14:10
Show Gist options
  • Save getchenge/b2ed3b35aab803f706a5 to your computer and use it in GitHub Desktop.
Save getchenge/b2ed3b35aab803f706a5 to your computer and use it in GitHub Desktop.
中间件例子_静态文件夹
var path = require('path');
var fs = require('fs');
var url = require('url');
var app = require('express')();
var staticfile = function (req,res,next) {
var pathname = url.parse(req.url).pathname;
fs.readFile(path.join(ROOT, pathname), function (err, file){
if(err){
return next();
}
res.writeHead(200);
res.end(file);
});
};
app.use('/public', staticFile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment