-
Notifications
You must be signed in to change notification settings - Fork 568
/
configuration.ts
53 lines (48 loc) 路 1.23 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
import {
Configuration,
Init,
Inject,
WEB_ROUTER_PARAM_KEY,
extractKoaLikeValue,
MidwayConfigService,
MidwayDecoratorService,
} from '@midwayjs/core';
import * as session from '@midwayjs/session';
import { MidwayKoaFramework } from './framework';
import * as DefaultConfig from './config/config.default';
import { BodyParserMiddleware } from './middleware/bodyparser.middleware';
import { SiteFileMiddleware } from './middleware/fav.middleware';
@Configuration({
namespace: 'koa',
imports: [session],
importConfigs: [
{
default: DefaultConfig,
},
],
})
export class KoaConfiguration {
@Inject()
decoratorService: MidwayDecoratorService;
@Inject()
koaFramework: MidwayKoaFramework;
@Inject()
configService: MidwayConfigService;
@Init()
init() {
// register param decorator
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() {
this.koaFramework.useMiddleware([SiteFileMiddleware, BodyParserMiddleware]);
}
}