![](/img/trans.png)
[英]How can I disable NodeJS Express for specific paths in my app and allow access to a specific regex in one of them?
[英]Deny access to specific directory in nodejs express
我試圖拒絕公眾使用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,我收到消息'Access Forbidden'但不是如果我路由到localhost / partials / files.html
有什么建議?
語句順序在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.