jj.js 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/router.js +7 -10
- package/lib/run.js +6 -1
- package/package.json +1 -1
package/lib/router.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const router = require('@koa/router')();
|
|
2
2
|
const {app: cfg_app, routes: cfg_routes} = require('./config');
|
|
3
3
|
const {toLine} = require('./utils/str');
|
|
4
|
-
const Logger = require('./logger');
|
|
5
4
|
const run = require('./run');
|
|
6
5
|
|
|
7
6
|
// 注册用户路由
|
|
@@ -27,21 +26,19 @@ if (cfg_routes) {
|
|
|
27
26
|
ctx.APP = paths[2] || cfg_app.default_app;
|
|
28
27
|
ctx.CONTROLLER = paths[1] || cfg_app.default_controller;
|
|
29
28
|
ctx.ACTION = paths[0] || cfg_app.default_action;
|
|
30
|
-
Logger.debug(`Router: {APP: ${ctx.APP}, CONTROLLER: ${ctx.CONTROLLER}, ACTION: ${ctx.ACTION}}`);
|
|
31
29
|
await run(ctx, next, item.type);
|
|
32
30
|
});
|
|
33
31
|
}
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
// 注册系统路由
|
|
37
|
-
router.all(cfg_app.app_multi ? '/:
|
|
38
|
-
ctx.APP = ctx.params.
|
|
39
|
-
ctx.CONTROLLER = ctx.params.
|
|
40
|
-
ctx.ACTION = ctx.params.
|
|
41
|
-
delete ctx.params.
|
|
42
|
-
delete ctx.params.
|
|
43
|
-
delete ctx.params.
|
|
44
|
-
Logger.debug(`Router: {APP: ${ctx.APP}, CONTROLLER: ${ctx.CONTROLLER}, ACTION: ${ctx.ACTION}}`);
|
|
35
|
+
router.all(cfg_app.app_multi ? '/:APP?/:CONTROLLER?/:ACTION?' : '/:CONTROLLER?/:ACTION?', async (ctx, next) => {
|
|
36
|
+
ctx.APP = ctx.params.APP || cfg_app.default_app;
|
|
37
|
+
ctx.CONTROLLER = ctx.params.CONTROLLER || cfg_app.default_controller;
|
|
38
|
+
ctx.ACTION = ctx.params.ACTION || cfg_app.default_action;
|
|
39
|
+
delete ctx.params.APP;
|
|
40
|
+
delete ctx.params.CONTROLLER;
|
|
41
|
+
delete ctx.params.ACTION;
|
|
45
42
|
await run(ctx, next);
|
|
46
43
|
});
|
|
47
44
|
|
package/lib/run.js
CHANGED
|
@@ -4,8 +4,13 @@ const {readFile} = require('./utils/fs');
|
|
|
4
4
|
const {toHump} = require('./utils/str');
|
|
5
5
|
const {app: cfg_app, view: cfg_view, db, page, log, cache, cookie, tpl} = require('./config');
|
|
6
6
|
const compose = require('koa-compose');
|
|
7
|
+
const Logger = require('./logger');
|
|
7
8
|
|
|
8
9
|
async function run(ctx, next, control_type=cfg_app.controller_folder) {
|
|
10
|
+
Logger.debug(ctx.request);
|
|
11
|
+
Logger.debug(`Router: {APP: '${ctx.APP}', CONTROLLER: '${ctx.CONTROLLER}', ACTION: '${ctx.ACTION}'}`);
|
|
12
|
+
Logger.debug('Params/Get/Post:', ctx.params, ctx.query, ctx.request.body);
|
|
13
|
+
|
|
9
14
|
// 设置根加载器
|
|
10
15
|
ctx.$ = loader('./', ctx);
|
|
11
16
|
ctx._ = loader(cfg_app.base_dir, ctx);
|
|
@@ -95,7 +100,7 @@ async function run(ctx, next, control_type=cfg_app.controller_folder) {
|
|
|
95
100
|
}
|
|
96
101
|
const Middleware = ctx._[APP]['middleware'][MIDDLEWARE];
|
|
97
102
|
if(!Middleware || typeof Middleware != 'function') {
|
|
98
|
-
throw new
|
|
103
|
+
throw new Error(`中间件文件:${APP}/middleware/${MIDDLEWARE}不存在!`);
|
|
99
104
|
}
|
|
100
105
|
const $middleware = new Middleware(ctx, next);
|
|
101
106
|
if(!$middleware[METHOD] || typeof $middleware[METHOD] != 'function') {
|