12345678910111213141516171819202122232425 |
- 'use strict';
- // 路由配置
- const rkey = 'inviteCode';
- const ckey = 'user.inviteCode';
- const keyZh = '邀请码';
- const routes = [
- { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
- ];
- module.exports = app => {
- const { router, config } = app;
- const mwares = app.middleware;
- console.log(`${keyZh}: ${rkey}`);
- for (const route of routes) {
- const { method, path, controller: ctl, zh } = route;
- let { middleware = [] } = route;
- if (!method || !path || !ctl) continue;
- // 拼全路径
- const allPath = `${config.routePrefix}/${path}`;
- // 处理中间件
- if (middleware.length > 0) middleware = middleware.map(i => mwares[i]({ enable: true }));
- // 注册路由
- router[method](zh, allPath, ...middleware, ctl);
- }
- };
|