12345678910111213141516171819202122232425262728293031323334353637383940 |
- const jwt = require("jsonwebtoken");
- // 200正常 201已经发送过请求,不要重复发送 300查询错误 405token过期 500错误
- const verifToken = (req, res, next) => {
- // console.log(ctx.request.url);js replace
- let url = req.url.split("?")[0];
- // console.log(url);
- // 以下接口不校验token
- let url_config = ["/api/pbl/login", "/api/pbl/login2", "/api/pbl/weChatCode","/api/pbl/selectUser"];
- // 检测接口是否不在校验接口列表中
- let changer = url_config.some((item) => {
- return item == url;
- });
- // console.log(changer);
- if (changer) {
- // 不检验token
- next();
- } else {
- // 检验token
- // console.log(req.headers["authorization"]);
- if (
- req.headers["authorization"] &&
- req.headers["authorization"] != "Bearer"
- ) {
- next()
- } else {
- // console.log(22);
- // res.send ({
- // code: 405,
- // msg: "请重新登录",
- // })
- next()
- }
- }
- };
- module.exports = verifToken;
|