2015-07-21 162 views
2

我有app.html在一个公共文件夹中,它正在提供静态文件来表达。允许访问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,我能直接注销以及之后访问它。

这里有什么问题?

回答

2

这个问题很可能是您在 之前您的app.get()一行。静态中间件检查文件是否存在,如果存在则发送。因此,您需要在之前将app.get()中间件放入您的express.static()中间件中。

+0

工作。万分感谢 。 –