0

这有效:

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。我在这里缺少什么?

4

2 回答 2

0

您应该将中间件更改为:

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.
于 2013-07-17T04:09:34.083 回答
0

app.use只接受一个参数。你需要把它分成两个app.use()s。

于 2013-07-17T02:20:26.897 回答