繁体   English   中英

express.static +中间件= 404

[英]express.static + middlware = 404

这有效:

http://localhost:3000/private/test2.html
app.use('/private',express.static(path.join(__dirname, 'private')));

但是,一旦添加中间件,就找不到该页面。

var secure = function(req,res,next) {
    console.log('in here' + req.url);
    next();
}
app.use('/private',secure,express.static(path.join(__dirname, 'private')));

有了中间件,我得到了404。我在这里缺少什么?

app.use只需要一个参数。 您需要将其拆分为两个app.use()

您应该将中间件更改为:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM