-
Notifications
You must be signed in to change notification settings - Fork 568
/
configuration.ts
63 lines (55 loc) · 1.47 KB
/
configuration.ts
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
63
import {
App,
Configuration,
Inject,
Init,
WEB_ROUTER_PARAM_KEY,
extractKoaLikeValue,
MidwayDecoratorService,
} from '@midwayjs/core';
import { IMidwayWebApplication } from './interface';
import { join } from 'path';
@Configuration({
namespace: 'egg',
importConfigs: [join(__dirname, 'config')],
})
export class EggConfiguration {
@Inject()
baseDir;
@Inject()
appDir;
@App()
app: IMidwayWebApplication;
@Inject()
decoratorService: MidwayDecoratorService;
@Init()
init() {
this.decoratorService.registerParameterHandler(
WEB_ROUTER_PARAM_KEY,
options => {
return extractKoaLikeValue(
options.metadata.type,
options.metadata.propertyData,
options.originParamType
)(options.originArgs[0], options.originArgs[1]);
}
);
}
async onReady() {
// ps: 本想在这里清理掉egg添加的中间件,但是这里的数组已经只有一个 midway root middleware,其他的 getter 都是 egg 加进去的,但是不会被中间件执行,所以不需要清理
// 去掉为了 egg-socket.io 报错扫进去的 session
this.app.middleware =
Array.isArray(this.app.middleware) && this.app.middleware.length
? this.app.middleware.slice()
: [];
}
async onServerReady() {
// trigger server didReady
if (this.app.messenger) {
this.app.messenger.emit('egg-ready');
}
}
async onStop() {
// TODO flush egg logger and close it
}
}