
一种快速的“肮脏”解决方案是将
.html请求附加到其中没有句点并且公共目录中存在HTML文件的请求中:
var fs = require('fs');var publicdir = __dirname + '/public';app.use(function(req, res, next) { if (req.path.indexOf('.') === -1) { var file = publicdir + req.path + '.html'; fs.exists(file, function(exists) { if (exists) req.url += '.html'; next(); }); } else next();});app.use(express.static(publicdir));欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)