interview.js 1.3 KB

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. // 路由配置
  3. const rkey = 'interview';
  4. const ckey = 'news.interview';
  5. const keyZh = '嘉宾访谈';
  6. const routes = [
  7. { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
  8. { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
  9. { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, name: `${ckey}Create`, zh: `创建${keyZh}` },
  10. { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
  11. { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
  12. ];
  13. module.exports = app => {
  14. const { router, config } = app;
  15. const mwares = app.middleware;
  16. console.log(`${keyZh}: ${rkey}`);
  17. for (const route of routes) {
  18. const { method, path, controller: ctl, zh } = route;
  19. let { middleware = [] } = route;
  20. if (!method || !path || !ctl) continue;
  21. // 拼全路径
  22. const allPath = `${config.routePrefix}/${path}`;
  23. // 处理中间件
  24. if (middleware.length > 0) middleware = middleware.map(i => mwares[i]({ enable: true }));
  25. // 注册路由
  26. router[method](zh, allPath, ...middleware, ctl);
  27. }
  28. };