拒绝访问nodejs 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,我得到消息“禁止访问”,但不是如果我路由到本地/ partials / files.html

任何build议?

语句的顺序在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')));