-
Notifications
You must be signed in to change notification settings - Fork 567
/
interface.ts
170 lines (152 loc) 路 3.76 KB
/
interface.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import { IConfigurationOptions, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
import * as koa from 'koa';
import { Context as KoaContext, DefaultState, Middleware, Next } from 'koa';
import { RouterParamValue } from '@midwayjs/core';
import * as qs from 'qs';
export interface State extends DefaultState {}
export type IMidwayKoaContext = IMidwayContext<KoaContext>;
export type IMidwayKoaApplication = IMidwayApplication<IMidwayKoaContext, koa<State, IMidwayKoaContext> & {
generateController(
controllerMapping: string,
routeArgsInfo?: RouterParamValue[],
routerResponseData?: any []
): Middleware<State, IMidwayKoaContext>;
/**
* @deprecated
* @param middlewareId
*/
generateMiddleware(middlewareId: any): Promise<Middleware<State, IMidwayKoaContext>>;
}>;
/**
* @deprecated use NextFunction definition
*/
export type IMidwayKoaNext = Next;
export type NextFunction = Next;
export interface IMidwayKoaConfigurationOptions extends IConfigurationOptions {
/**
* cookies sign keys
*/
keys?: string[];
/**
* application http port
*/
port?: number;
/**
* application hostname, 127.0.0.1 as default
*/
hostname?: string;
/**
* https key
*/
key?: string | Buffer | Array<Buffer | Object>;
/**
* https cert
*/
cert?: string | Buffer | Array<string | Buffer>;
/**
* https ca
*/
ca?: string | Buffer | Array<string | Buffer>;
/**
* http2 support
*/
http2?: boolean;
/**
* http global prefix
*/
globalPrefix?: string;
/**
* Trust proxy headers
*/
proxy?: boolean;
/**
* Subdomain offset
*/
subdomainOffset?: number;
/**
* Proxy IP header, defaults to X-Forwarded-For
*/
proxyIpHeader?: string;
/**
* Max IPs read from proxy IP header, default to 0 (means infinity)
*/
maxIpsCount?: number;
/**
* server timeout in milliseconds, default to 2 minutes.
*
* for special request, just use `ctx.req.setTimeout(ms)`
*
* @see https://nodejs.org/api/http.html#http_server_timeout
*/
serverTimeout?: number;
/**
* qs mode
*/
queryParseMode?: 'extended' | 'strict' | 'first';
/**
* qs options
*/
queryParseOptions?: qs.IParseOptions;
/*
* https/https/http2 server options
*/
serverOptions?: Record<string, any>;
}
export type MiddlewareParamArray = Array<
Middleware<DefaultState, IMidwayKoaContext>
>;
export interface IWebMiddleware {
resolve(): koa.Middleware<DefaultState, IMidwayKoaContext>;
}
export type Application = IMidwayKoaApplication;
export interface Context extends IMidwayKoaContext {
state: State;
}
export interface BodyParserOptions {
enable?: boolean;
/**
* parser will only parse when request type hits enableTypes, default is ['json', 'form'].
*/
enableTypes?: string[];
/**
* requested encoding. Default is utf-8 by co-body
*/
encoding?: string;
/**
* limit of the urlencoded body. If the body ends up being larger than this limit
* a 413 error code is returned. Default is 56kb
*/
formLimit?: string;
/**
* limit of the json body. Default is 1mb
*/
jsonLimit?: string;
/**
* limit of the text body. Default is 1mb.
*/
textLimit?: string;
/**
* limit of the xml body. Default is 1mb.
*/
xmlLimit?: string;
/**
* when set to true, JSON parser will only accept arrays and objects. Default is true
*/
strict?: boolean;
/**
* custom json request detect function. Default is null
*/
detectJSON?: (ctx: IMidwayKoaContext) => boolean;
/**
* support extend types
*/
extendTypes?: {
json?: string[] | string | undefined;
form?: string[] | string | undefined;
text?: string[] | string | undefined;
};
/**
* support custom error handle
*/
onerror?: (err: Error, ctx: IMidwayKoaContext) => void;
}