@midwayjs/web 3.4.6 → 3.4.9
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/app/extend/request.js +23 -0
- package/app.js +21 -0
- package/dist/config/config.default.js +1 -0
- package/dist/framework/web.js +0 -16
- package/dist/interface.d.ts +4 -0
- package/package.json +4 -4
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _querycache = Symbol('_querycache');
|
|
4
|
+
const qs = require('querystring');
|
|
5
|
+
|
|
6
|
+
function firstValue(value) {
|
|
7
|
+
if (Array.isArray(value)) {
|
|
8
|
+
value = value[0];
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
get query() {
|
|
15
|
+
if (this.app.config.egg.queryParseMode === 'simple') {
|
|
16
|
+
const str = this.querystring;
|
|
17
|
+
const c = (this._querycache = this._querycache || {});
|
|
18
|
+
return c[str] || (c[str] = qs.parse(str));
|
|
19
|
+
} else {
|
|
20
|
+
return this._customQuery(_querycache, firstValue);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
};
|
package/app.js
CHANGED
|
@@ -62,6 +62,27 @@ class AppBootHook {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
const bodyPatch = async (ctx, next) => {
|
|
66
|
+
await next();
|
|
67
|
+
if (
|
|
68
|
+
ctx.body === undefined &&
|
|
69
|
+
!ctx.response._explicitStatus &&
|
|
70
|
+
ctx._matchedRoute
|
|
71
|
+
) {
|
|
72
|
+
// 如果进了路由,重新赋值,防止 404
|
|
73
|
+
ctx.body = undefined;
|
|
74
|
+
}
|
|
75
|
+
if (
|
|
76
|
+
ctx.response._midwayControllerNullBody &&
|
|
77
|
+
ctx.body &&
|
|
78
|
+
ctx.status === 204
|
|
79
|
+
) {
|
|
80
|
+
ctx.status = 200;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
this.app.getMiddleware().insertAfter(bodyPatch, 'notfound');
|
|
85
|
+
|
|
65
86
|
const eggRouterMiddleware = this.app.router.middleware();
|
|
66
87
|
eggRouterMiddleware._name = 'eggRouterMiddleware';
|
|
67
88
|
this.app.useMiddleware(eggRouterMiddleware);
|
package/dist/framework/web.js
CHANGED
|
@@ -80,24 +80,8 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
80
80
|
throw new core_1.httpError.NotFoundError(`${ctx.path} Not Found`);
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
-
const bodyPatch = async (ctx, next) => {
|
|
84
|
-
await next();
|
|
85
|
-
if (ctx.body === undefined &&
|
|
86
|
-
!ctx.response._explicitStatus &&
|
|
87
|
-
ctx._matchedRoute) {
|
|
88
|
-
// 如果进了路由,重新赋值,防止 404
|
|
89
|
-
ctx.body = undefined;
|
|
90
|
-
}
|
|
91
|
-
if (ctx.response._midwayControllerNullBody &&
|
|
92
|
-
ctx.body &&
|
|
93
|
-
ctx.status === 204) {
|
|
94
|
-
ctx.status = 200;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
83
|
// insert error handler
|
|
98
84
|
const midwayRootMiddleware = async (ctx, next) => {
|
|
99
|
-
// this.app.createAnonymousContext(ctx);
|
|
100
|
-
this.middlewareManager.insertAfter(bodyPatch, 'notfound');
|
|
101
85
|
await (await this.applyMiddleware(midwayRouterNotFound))(ctx, next);
|
|
102
86
|
};
|
|
103
87
|
this.app.use(midwayRootMiddleware);
|
package/dist/interface.d.ts
CHANGED
|
@@ -101,6 +101,10 @@ export interface IMidwayWebConfigurationOptions extends IConfigurationOptions {
|
|
|
101
101
|
* http global prefix
|
|
102
102
|
*/
|
|
103
103
|
globalPrefix?: string;
|
|
104
|
+
/**
|
|
105
|
+
* http query parser mode, default is extended
|
|
106
|
+
*/
|
|
107
|
+
queryParseMode?: 'simple' | 'extended';
|
|
104
108
|
}
|
|
105
109
|
/**
|
|
106
110
|
* @deprecated since version 3.0.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/web",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.9",
|
|
4
4
|
"description": "Midway Web Framework for Egg.js",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@midwayjs/decorator": "^3.4.4",
|
|
32
32
|
"@midwayjs/logger": "^2.15.0",
|
|
33
|
-
"@midwayjs/mock": "^3.4.
|
|
33
|
+
"@midwayjs/mock": "^3.4.9",
|
|
34
34
|
"axios": "0.27.2",
|
|
35
35
|
"dayjs": "1.11.4",
|
|
36
36
|
"egg-logger": "2.9.0",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@eggjs/router": "^2.0.0",
|
|
50
|
-
"@midwayjs/core": "^3.4.
|
|
50
|
+
"@midwayjs/core": "^3.4.9",
|
|
51
51
|
"egg": "^2.28.0",
|
|
52
52
|
"egg-cluster": "^1.27.1",
|
|
53
53
|
"find-up": "5.0.0",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"engines": {
|
|
62
62
|
"node": ">=12"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "bc8113cff70d88a31e44bde69c395f61a7de2045"
|
|
65
65
|
}
|