我正在使用一种相当丑陋的方法:
var app = require('express')(),
server = require('http').createServer(app),
fs = require('fs');
server.listen(80);
path = "/Users/my/path/";
var served_files = {};
["myfile1.html","myfile2.html","myfile3.html"].forEach(function(file){
served_files["/"+file] = fs.readFileSync(path+file,"utf8");
});
app.use(function(req,res){
if (served_files[req.path])
res.send(files[req.path]);
});
正确的方法是什么?