@midwayjs/koa 4.0.0-beta.11 → 4.0.0-beta.12
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 +42 -7
- package/dist/onerror.js +1 -1
- package/dist/utils.js +4 -2
- package/package.json +7 -7
package/dist/framework.js
CHANGED
|
@@ -157,13 +157,48 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
157
157
|
// root middleware
|
|
158
158
|
const midwayRootMiddleware = async (ctx, next) => {
|
|
159
159
|
this.app.createAnonymousContext(ctx);
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
+
});
|
|
167
202
|
};
|
|
168
203
|
this.app.use(midwayRootMiddleware);
|
|
169
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/koa",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.12",
|
|
4
4
|
"description": "Midway Web Framework for KOA",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@midwayjs/core": "^4.0.0-beta.
|
|
28
|
-
"@midwayjs/mock": "^4.0.0-beta.
|
|
27
|
+
"@midwayjs/core": "^4.0.0-beta.12",
|
|
28
|
+
"@midwayjs/mock": "^4.0.0-beta.12",
|
|
29
29
|
"@types/koa-router": "7.4.9",
|
|
30
30
|
"axios": "1.12.0",
|
|
31
31
|
"fs-extra": "11.3.3"
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@koa/router": "^12.0.0",
|
|
35
35
|
"@midwayjs/cookies": "^1.3.0",
|
|
36
|
-
"@midwayjs/session": "^4.0.0-beta.
|
|
36
|
+
"@midwayjs/session": "^4.0.0-beta.12",
|
|
37
37
|
"@types/koa": "3.0.0",
|
|
38
|
-
"@types/qs": "6.
|
|
38
|
+
"@types/qs": "6.14.0",
|
|
39
39
|
"koa": "3.0.3",
|
|
40
40
|
"koa-bodyparser": "4.4.1",
|
|
41
|
-
"qs": "6.14.
|
|
41
|
+
"qs": "6.14.2"
|
|
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": "1c48179b7c827ba8ec9351e9b6c36ec1726d3e11"
|
|
52
52
|
}
|