inviteCode.js 824 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. // 路由配置
  3. const rkey = 'inviteCode';
  4. const ckey = 'user.inviteCode';
  5. const keyZh = '邀请码';
  6. const routes = [
  7. { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
  8. ];
  9. module.exports = app => {
  10. const { router, config } = app;
  11. const mwares = app.middleware;
  12. console.log(`${keyZh}: ${rkey}`);
  13. for (const route of routes) {
  14. const { method, path, controller: ctl, zh } = route;
  15. let { middleware = [] } = route;
  16. if (!method || !path || !ctl) continue;
  17. // 拼全路径
  18. const allPath = `${config.routePrefix}/${path}`;
  19. // 处理中间件
  20. if (middleware.length > 0) middleware = middleware.map(i => mwares[i]({ enable: true }));
  21. // 注册路由
  22. router[method](zh, allPath, ...middleware, ctl);
  23. }
  24. };