一个服务端的登录拦截

var express = require('express');
var app = express();

//登录拦截,如果未登录,部分操作被禁用
app.use(function (req, res, next) {
  if (req.cookies.userId) {
    next(); //已登录
  } else {
    //白名单
    // console.log("req.originalUrl", req.originalUrl);
    if (req.path == '/users/login' || req.path == '/users/logout' || req.path == '/goods/list' || req.path == '/users/register') {
      next();
    } else {
      res.json({
        status: '10001',
        msg: '当前未登录',
        result: ''
      })
    }
  }
})

  此处使用的node的一个框架express

猜你喜欢

转载自www.cnblogs.com/baixinL/p/11933164.html