我在一个提供静态文件的公共文件夹中有app.html
。
我使用了here的代码。
但是,不是来自视图文件夹中的profile.ejs
(根据链接中的代码),我想从公共文件夹内部提供app.html
。
app.get('/app.html', isLoggedIn, function(req, res) {
res.render('app.html'/*, {
user : req.user // get the user out of session and pass to template
}*/);
console.log("APP.HTML");
});
function isLoggedIn(req, res, next) {
// if user is authenticated in the session, carry on
if (req.isAuthenticated())
return next();
// if they aren't redirect them to the home page
res.redirect('/');
}
但它并不限制对loggedIn
用户的访问权限,我也可以在注销后直接访问它。
这里可能有什么问题?
答案 0 :(得分:2)
问题很可能是您在express.static()
行之前app.get()
。静态中间件检查文件是否存在,如果存在则发送。因此,您需要在 app.get()
中间件之前添加express.static()
。