我正在使用带有express.js的node.js。 这是我的公共目录结构:
public/
js/
css/
images/
built/
main-built.js
main-built.css
index.html
dev.html
其中index.html
链接到js/
和css/
脚本,而dev.html
链接到main-built.js
和main-built.css
。 当应用程序作为生产模式启动时,如何在public/
( js/*
, css/*
和dev.html
)下动态禁止某些路径?
如果您使用的是Express,则可以使用一小块中间件阻止它们。
app.configure(function() {
app.use(function(req, res, next) {
if(process.env.NODE_ENV === 'production') {
if( /* check req.url for blocked content */) {
res.send('Access Denied');
}
}
else {
// Not in production, proceed to next handler.
next();
}
});
app.use(express.static(__dirname + '/public'));
});