我正在使用Node Express尝试拒绝公众查看特定目录中的文件,以下是代码:
如果我路由到 localhost/partials,我会收到“访问被禁止”的消息,但如果我路由到 localhost/partials/files.html,则不会收到该消息。
有什么建议吗?
我正在使用Node Express尝试拒绝公众查看特定目录中的文件,以下是代码:
app.use(express.static(path.join(__dirname, 'partials')));
app.all('/partials/*', function (req,res, next) {
res.status(403).send(
{
message: 'Access Forbidden'
});
next();
});
如果我路由到 localhost/partials,我会收到“访问被禁止”的消息,但如果我路由到 localhost/partials/files.html,则不会收到该消息。
有什么建议吗?
options
的作用是什么? - Mukesh Sharmaapp.use(express.static(path.join(__dirname, 'partials')));
的意思是localhost/files.html
可以访问partials
文件夹中的所有静态内容。 - Mukesh Sharma