'use strict'; const _ = require('lodash'); const whiteList = [ '/util/crk', '/admin/login', '/user/wxLogin', '/user/login', '/user' ]; 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(); } } }; };