Created
June 29, 2014 14:10
-
-
Save getchenge/b2ed3b35aab803f706a5 to your computer and use it in GitHub Desktop.
中间件例子_静态文件夹
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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