|
@@ -0,0 +1,28 @@
|
|
|
+'use strict';
|
|
|
+// 测试接口
|
|
|
+const rKey = 'scenedata'; // routerKey,路由前缀变量
|
|
|
+const cKey = 'scenedata'; // controllerKey,controller名
|
|
|
+const zhKey = '视频场景信息';
|
|
|
+const routes = [
|
|
|
+ { method: 'get', path: `/${rKey}`, controller: `${cKey}.index`, name: `${cKey}Query`, zh: `${zhKey}列表查询` },
|
|
|
+ { method: 'get', path: `/${rKey}/:id`, controller: `${cKey}.show`, name: `${cKey}Show`, zh: `${zhKey}查询` },
|
|
|
+ { method: 'post', path: `/${rKey}`, controller: `${cKey}.create`, name: `${cKey}Create`, zh: `创建${zhKey}` },
|
|
|
+ { method: 'post', path: `/${rKey}/:id`, controller: `${cKey}.update`, name: `${cKey}Update`, zh: `修改${zhKey}` },
|
|
|
+ { method: 'delete', path: `/${rKey}/:id`, controller: `${cKey}.destroy`, name: `${cKey}Delete`, zh: `删除${zhKey}` },
|
|
|
+];
|
|
|
+
|
|
|
+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);
|
|
|
+ }
|
|
|
+};
|