Express拦截器

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('/');
    }
  }
});
//-------------------------------------------------------------

posted on 2019-10-11 10:40  _xinT  阅读(824)  评论(0编辑  收藏  举报