@midwayjs/koa 4.0.0-beta.8 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/framework.js +49 -8
- package/dist/onerror.js +1 -1
- package/dist/utils.js +4 -2
- package/index.d.ts +5 -0
- package/package.json +9 -9
package/dist/framework.js
CHANGED
|
@@ -115,7 +115,13 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
115
115
|
return c[str];
|
|
116
116
|
if (self.configurationOptions.queryParseMode) {
|
|
117
117
|
// use qs module to parse query
|
|
118
|
-
|
|
118
|
+
const parseOptions = {
|
|
119
|
+
...self.configurationOptions.queryParseOptions,
|
|
120
|
+
...(self.configurationOptions.queryParseMode === 'first'
|
|
121
|
+
? { duplicates: 'first' }
|
|
122
|
+
: {}),
|
|
123
|
+
};
|
|
124
|
+
c[str] = qs.parse(str, parseOptions);
|
|
119
125
|
}
|
|
120
126
|
else {
|
|
121
127
|
// use querystring to parse query by default
|
|
@@ -151,13 +157,48 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
151
157
|
// root middleware
|
|
152
158
|
const midwayRootMiddleware = async (ctx, next) => {
|
|
153
159
|
this.app.createAnonymousContext(ctx);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
const traceService = this.applicationContext.get(core_1.MidwayTraceService);
|
|
161
|
+
const spanName = `${ctx.method} ${ctx.path || '/'}`;
|
|
162
|
+
const traceMetaResolver = this.configurationOptions?.tracing
|
|
163
|
+
?.meta;
|
|
164
|
+
const traceEnabled = this.configurationOptions?.tracing?.enable !== false;
|
|
165
|
+
const traceExtractor = this.configurationOptions?.tracing
|
|
166
|
+
?.extractor;
|
|
167
|
+
const traceInjector = this.configurationOptions?.tracing
|
|
168
|
+
?.injector;
|
|
169
|
+
const requestCarrier = typeof traceExtractor === 'function'
|
|
170
|
+
? traceExtractor({
|
|
171
|
+
ctx,
|
|
172
|
+
request: ctx.request,
|
|
173
|
+
response: ctx.response,
|
|
174
|
+
})
|
|
175
|
+
: ctx.headers;
|
|
176
|
+
const responseCarrier = typeof traceInjector === 'function'
|
|
177
|
+
? traceInjector({ ctx, request: ctx.request, response: ctx.response })
|
|
178
|
+
: ctx.response.res;
|
|
179
|
+
await traceService.runWithEntrySpan(spanName, {
|
|
180
|
+
enable: traceEnabled,
|
|
181
|
+
carrier: requestCarrier,
|
|
182
|
+
responseCarrier,
|
|
183
|
+
attributes: {
|
|
184
|
+
'midway.protocol': 'http',
|
|
185
|
+
},
|
|
186
|
+
meta: traceMetaResolver,
|
|
187
|
+
metaArgs: {
|
|
188
|
+
ctx,
|
|
189
|
+
carrier: requestCarrier,
|
|
190
|
+
request: ctx.request,
|
|
191
|
+
response: ctx.response,
|
|
192
|
+
},
|
|
193
|
+
}, async () => {
|
|
194
|
+
await (await this.applyMiddleware(applyMiddlewares))(ctx, next);
|
|
195
|
+
if (ctx.body === undefined &&
|
|
196
|
+
!ctx.response._explicitStatus &&
|
|
197
|
+
ctx._matchedRoute) {
|
|
198
|
+
// 如果进了路由,重新赋值,防止 404
|
|
199
|
+
ctx.body = undefined;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
161
202
|
};
|
|
162
203
|
this.app.use(midwayRootMiddleware);
|
|
163
204
|
this.webRouterService = await this.applicationContext.getAsync(core_1.MidwayWebRouterService, [
|
package/dist/onerror.js
CHANGED
package/dist/utils.js
CHANGED
|
@@ -37,7 +37,9 @@ function sendToWormhole(stream) {
|
|
|
37
37
|
return resolve();
|
|
38
38
|
}
|
|
39
39
|
// unpipe it
|
|
40
|
-
|
|
40
|
+
if (stream.unpipe) {
|
|
41
|
+
stream.unpipe();
|
|
42
|
+
}
|
|
41
43
|
// enable resume first
|
|
42
44
|
stream.resume();
|
|
43
45
|
if (stream._readableState && stream._readableState.ended) {
|
|
@@ -125,7 +127,7 @@ function escapeHtml(string) {
|
|
|
125
127
|
}
|
|
126
128
|
let escape;
|
|
127
129
|
let html = '';
|
|
128
|
-
let index
|
|
130
|
+
let index;
|
|
129
131
|
let lastIndex = 0;
|
|
130
132
|
for (index = match.index; index < str.length; index++) {
|
|
131
133
|
switch (str.charCodeAt(index)) {
|
package/index.d.ts
CHANGED
|
@@ -15,6 +15,11 @@ declare module '@midwayjs/core/dist/interface' {
|
|
|
15
15
|
keys?: string | string[];
|
|
16
16
|
koa?: IMidwayKoaConfigurationOptions;
|
|
17
17
|
cookies?: CookieSetOptions;
|
|
18
|
+
cookiesExtra?: {
|
|
19
|
+
defaultGetOptions?: {
|
|
20
|
+
sign?: boolean;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
18
23
|
/**
|
|
19
24
|
* onerror middleware options
|
|
20
25
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/koa",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Midway Web Framework for KOA",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -24,21 +24,21 @@
|
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@midwayjs/core": "^4.0.0
|
|
28
|
-
"@midwayjs/mock": "^4.0.0
|
|
27
|
+
"@midwayjs/core": "^4.0.0",
|
|
28
|
+
"@midwayjs/mock": "^4.0.0",
|
|
29
29
|
"@types/koa-router": "7.4.9",
|
|
30
|
-
"axios": "1.
|
|
31
|
-
"fs-extra": "11.3.
|
|
30
|
+
"axios": "1.13.5",
|
|
31
|
+
"fs-extra": "11.3.3"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@koa/router": "^12.0.0",
|
|
35
35
|
"@midwayjs/cookies": "^1.3.0",
|
|
36
|
-
"@midwayjs/session": "^4.0.0
|
|
36
|
+
"@midwayjs/session": "^4.0.0",
|
|
37
37
|
"@types/koa": "3.0.0",
|
|
38
|
-
"@types/qs": "6.
|
|
38
|
+
"@types/qs": "6.15.0",
|
|
39
39
|
"koa": "3.0.3",
|
|
40
40
|
"koa-bodyparser": "4.4.1",
|
|
41
|
-
"qs": "6.
|
|
41
|
+
"qs": "6.15.0"
|
|
42
42
|
},
|
|
43
43
|
"author": "Harry Chen <czy88840616@gmail.com>",
|
|
44
44
|
"repository": {
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": ">=20"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "014f32c23ebc1d5ac21777c76be2fd373ce992d8"
|
|
52
52
|
}
|