Node.JS express app.use不';无法根据图像请求调用
当请求Node.JS express app.use不';无法根据图像请求调用,node.js,express,Node.js,Express,当请求/uploads/private/中的图像时,我希望客户端提供用户名/密码,以确保他们有权查看此目录中的文件。我有一个应用程序。在这里使用方法: app.use(function(req, res, next) { if (req.user == null && req.path.indexOf('/uploads/private') === 0) { res.send(JSON.stringify({status: 0, error: "Not authentic
/uploads/private/
中的图像时,我希望客户端提供用户名/密码,以确保他们有权查看此目录中的文件。我有一个应用程序。在这里使用方法:
app.use(function(req, res, next) {
if (req.user == null && req.path.indexOf('/uploads/private') === 0) {
res.send(JSON.stringify({status: 0, error: "Not authenticated"}));
res.end();
return;
} else {
console.log(req.path);
}
next();
});
但是,当我从我的服务器请求映像时,不会调用它,只有在请求其他任何内容时才会调用它。如何确保从该目录检索图像时调用此函数?您应该在所有路由之前调用此函数它已经在我的所有路由之前。