'use strict'; // 路由配置 const mainKey = 'duplicate'; const keyZh = '绩效申请已通过'; const routes = [ { method: 'get', path: `/${mainKey}`, controller: `${mainKey}.index`, name: `${mainKey}Query`, zh: `${keyZh}设置列表查询` }, { method: 'get', path: `/${mainKey}/:id`, controller: `${mainKey}.show`, name: `${mainKey}Fetch`, zh: `${keyZh}设置查询` }, // { method: 'post', path: `/${mainKey}`, controller: `${mainKey}.create`, name: `${mainKey}Create`, zh: `创建${keyZh}设置` }, // { method: 'post', path: `/${mainKey}/:id`, controller: `${mainKey}.update`, name: `${mainKey}Update`, zh: `修改${keyZh}` }, // { method: 'delete', path: `/${mainKey}/:id`, controller: `${mainKey}.destroy`, name: `${mainKey}Delete`, zh: `删除${keyZh}` }, ]; module.exports = app => { const { router, config } = app; const mwares = app.middleware; 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]()); // 注册路由 router[method](zh, allPath, ...middleware, ctl); } };