[英]Deny access to specific directory in nodejs express
I am trying to deny public to see files in a special directory using node express following is the code: 我试图拒绝公众使用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();
});
If i route to localhost/partials, i get the message 'Access Forbidden' But not if i route to localhost/partials/files.html 如果我路由到localhost / partials,我收到消息'Access Forbidden'但不是如果我路由到localhost / partials / files.html
Any recommendations? 有什么建议?
Order of statements matter in node.js
. 语句顺序在node.js
。
app.all('/partials/*', function (req,res, next) {
res.status(403).send({
message: 'Access Forbidden'
});
});
//this line is used to load resources at localhost/partials/api.html
//but, because of above code snippets, we have blocked /partials/* routes
//hence, this line will practically wont work.
app.use('/partials',express.static(path.join(__dirname, 'partials')));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.