我正在尝试执行以下操作。
这里我尝试了什么?但它并没有像预期的那样工作:
var staticMiddlewarePrivate = express['static'](__dirname + '/public');
app.use(/^\/(?!oauth).*/, function(req, res, next) {
if (req.user == null) {
console.log("doing redirect as not login");
res.redirect('/oauth/login');
return;
}
console.log("user logged in");
staticMiddlewarePrivate(req, res, next);
});
我该如何解决这个问题?
答案 0 :(得分:0)
诀窍是在动态之后放置静态路由:
app.use(/^\/(?!oauth).*/, function(req, res, next) {
if (req.user == null) {
console.log("doing redirect as not login");
res.redirect('/oauth/login');
return;
}
console.log("user logged in");
next()
});
app.use(express.static(__dirname + '/public') );