/
configuration.ts
76 lines (69 loc) 路 1.62 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
64
65
66
67
68
69
70
71
72
73
74
75
76
import {
ApplicationContext,
Configuration,
Init,
Inject,
LOGGER_KEY,
PLUGIN_KEY,
WEB_ROUTER_PARAM_KEY,
extractKoaLikeValue,
MidwayDecoratorService,
REQUEST_OBJ_CTX_KEY,
} from '@midwayjs/core';
import { MidwayFaaSFramework } from './framework';
import * as DefaultConfig from './config.default';
@Configuration({
namespace: 'faas',
importConfigs: [
{
default: DefaultConfig,
},
],
})
export class FaaSConfiguration {
@Inject()
framework: MidwayFaaSFramework;
@Inject()
decoratorService: MidwayDecoratorService;
@ApplicationContext()
applicationContext;
@Init()
async init() {
this.decoratorService.registerPropertyHandler(
PLUGIN_KEY,
(key, meta, target) => {
return (
target?.[REQUEST_OBJ_CTX_KEY]?.[key] ||
this.framework.getApplication()[key]
);
}
);
this.decoratorService.registerPropertyHandler(
LOGGER_KEY,
(key, meta, target) => {
return (
target?.[REQUEST_OBJ_CTX_KEY]?.['logger'] ||
this.framework.getLogger()
);
}
);
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(container) {}
async onServerReady() {
if (!this.framework.isEnable()) {
// just in legacy local dev and test
await this.framework.run();
}
await this.framework.loadFunction();
}
}