@midwayjs/web 3.4.7 → 3.4.8-beta.1

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.
@@ -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);
@@ -40,6 +40,7 @@ exports.default = appInfo => {
40
40
  ctx.url;
41
41
  return `${info.timestamp} ${info.LEVEL} ${info.pid} [${label}] ${info.message}`;
42
42
  },
43
+ queryParseMode: 'extended',
43
44
  };
44
45
  exports.pluginOverwrite = false;
45
46
  exports.security = {
@@ -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);
@@ -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.7",
3
+ "version": "3.4.8-beta.1",
4
4
  "description": "Midway Web Framework for Egg.js",
5
5
  "main": "dist/index",
6
6
  "typings": "index.d.ts",
@@ -61,5 +61,5 @@
61
61
  "engines": {
62
62
  "node": ">=12"
63
63
  },
64
- "gitHead": "3c60619a65c6776d99fbf0b30ac454d3cb6926b9"
64
+ "gitHead": "a603d2348d6141f8f723901498f03a162a037708"
65
65
  }