簡體   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