'use strict'; const _ = require('lodash'); const whiteList = [ '/util/crk', // 生成rk '/admin/login', // 管理登陆 '/user/wxLogin', // 用户微信登陆 '/user/login', // 用户密码登录 '/user', // 创建用户 '/pay/order', // 支付回调 ]; module.exports = options => { return async function checkuserrk(ctx, next) { const request = _.get(ctx, 'request'); const method = _.get(request, 'method'); const uri = _.get(request, 'url'); // 本地或局域网请求,放过 if (process.env.NODE_ENV === 'development') await next(); // get方法放过 else if (method === 'GET') await next(); else { // 白名单中的路由放过: 查看是否以白名单中每一项为结尾,如果是的话,那就说明这个路由不需要检查requestKey const inWhiteList = whiteList.find(f => _.endsWith(uri, f)); if (inWhiteList) await next(); // 管理员的post放过 else if (ctx.admin) await next(); // 检查rk else { await ctx.service.util.rk.urk(); await next(); } } }; };