forked from jianghujs/jianghu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (51 loc) · 1.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict';
const path = require('path');
const egg = require('egg');
const EGG_PATH = Symbol.for('egg#eggPath');
const EGG_LOADER = Symbol.for('egg#loader');
class AppWorkerLoader extends egg.AppWorkerLoader {
loadConfig() {
super.loadConfig();
}
loadRouter() {
// super.loadRouter();
this.initJianghuRouter();
}
// 之前加载的 controller 不算数了,重新加载项目+框架的 app/controller 目录
initJianghuRouter() {
this.loadController({
directory: this.getLoadUnits().map(unit => path.join(unit.path, 'app/controller')),
// 让 controller 也支持 override
override: true,
});
this.getLoadUnits().reverse().forEach(unit =>
this.loadFile(path.join(unit.path, 'app/router.js'))
);
}
// 让 service 也支持 override
loadService(opt) {
opt = Object.assign({
override: true,
}, opt);
super.loadService(opt);
}
}
class Application extends egg.Application {
get [EGG_PATH]() {
return __dirname;
}
// 覆盖 Egg 的 Loader,启动时使用这个 Loader
get [EGG_LOADER]() {
return AppWorkerLoader;
}
}
class Agent extends egg.Agent {
get [EGG_PATH]() {
return __dirname;
}
}
module.exports = Object.assign(egg, {
AppWorkerLoader,
Application,
Agent,
});