checkUserRK.js 902 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. const _ = require('lodash');
  3. const whiteList = [ '/util/crk', '/admin/login', '/user/wxLogin', '/user/login', '/user' ];
  4. module.exports = options => {
  5. return async function checkuserrk(ctx, next) {
  6. const request = _.get(ctx, 'request');
  7. const method = _.get(request, 'method');
  8. const uri = _.get(request, 'url');
  9. if (process.env.NODE_ENV === 'development') await next();
  10. // get方法放过
  11. else if (method === 'GET') await next();
  12. else {
  13. // 白名单中的路由放过: 查看是否以白名单中每一项为结尾,如果是的话,那就说明这个路由不需要检查requestKey
  14. const inWhiteList = whiteList.find(f => _.endsWith(uri, f));
  15. if (inWhiteList) await next();
  16. // 管理员的post放过
  17. else if (ctx.admin) await next();
  18. // 检查rk
  19. else {
  20. await ctx.service.util.rk.urk();
  21. }
  22. }
  23. };
  24. };