https://cnodejs.org/topic/512d8172df9e9fcc58333c73
Express+Nodejs 下的登录拦截实现
app.js中:
//-----------拦截器的实现-------------------------------------
var openPage = ['/','/users/zhuce','/users/login','/users/logout'];
app.use(function(req, res, next) {
var url = req.originalUrl;
if(openPage.indexOf(url)>-1){
next();
}else{
if(req.session.loginbean){
next();
}else{
res.redirect('/');
}
}
});
//-------------------------------------------------------------