[英]express.static + middlware = 404
This works: 这有效:
http://localhost:3000/private/test2.html
app.use('/private',express.static(path.join(__dirname, 'private')));
However as soon as I add middleware, the page can't be found. 但是,一旦添加中间件,就找不到该页面。
var secure = function(req,res,next) {
console.log('in here' + req.url);
next();
}
app.use('/private',secure,express.static(path.join(__dirname, 'private')));
With the middleware in place I get a 404. What am I missing here? 有了中间件,我得到了404。我在这里缺少什么?
app.use
only takes one parameter. app.use
只需要一个参数。 you need to split it into two app.use()
s. 您需要将其拆分为两个
app.use()
。
You should change the middleware to this : 您应该将中间件更改为:
app.use(secure);
// use the middleware function
app.use('/private',express.static(path.join(__dirname, 'private')));
// serve static files from private subfolder using 'private/' as matching prefix
// static should be used at the end as it finishes the response.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.