@midwayjs/web 3.0.0-beta.5 → 3.0.0-beta.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/CHANGELOG.md CHANGED
@@ -3,6 +3,47 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
7
+
8
+ **Note:** Version bump only for package @midwayjs/web
9
+
10
+
11
+
12
+
13
+
14
+ # [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * express routing middleware takes effect at the controller level ([#1364](https://github.com/midwayjs/midway/issues/1364)) ([b9272e0](https://github.com/midwayjs/midway/commit/b9272e0971003443304b0c53815be31a0061b4bd))
20
+
21
+
22
+
23
+
24
+
25
+ # [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * middleware with ctx.body ([#1389](https://github.com/midwayjs/midway/issues/1389)) ([77af5c0](https://github.com/midwayjs/midway/commit/77af5c0b456f1843f4dcfd3dbfd2c0aa244c51bd))
31
+
32
+
33
+
34
+
35
+
36
+ # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * class transformer method missing ([#1387](https://github.com/midwayjs/midway/issues/1387)) ([074e839](https://github.com/midwayjs/midway/commit/074e8393598dc95e2742f735df75a2191c5fe25d))
42
+
43
+
44
+
45
+
46
+
6
47
  # [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
7
48
 
8
49
  **Note:** Version bump only for package @midwayjs/web
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  this is a sub package for midway.
7
7
 
8
- Document: [https://midwayjs.org/midway](https://midwayjs.org/midway)
8
+ Document: [https://midwayjs.org](https://midwayjs.org)
9
9
 
10
10
  ## License
11
11
 
package/app.js CHANGED
@@ -24,10 +24,9 @@ class AppBootHook {
24
24
  async didLoad() {
25
25
  debug('[egg lifecycle]: app didLoad');
26
26
  if (this.app.loader['useEggSocketIO']) {
27
- // socketio 下会提前加入 session 中间件,这里删除,防止重复加载
28
- if (this.app.middleware.length && this.app.middleware[this.app.middleware.length - 1]._name === 'session') {
29
- this.app.middleware.pop();
30
- }
27
+ // egg socket.io 需要这个中间件
28
+ // const session = this.app.getMiddleware().findItem('session');
29
+ // this.app.middleware.push(session);
31
30
  }
32
31
  }
33
32
 
@@ -6,7 +6,7 @@ export declare class EggConfiguration {
6
6
  app: IMidwayWebApplication;
7
7
  decoratorService: MidwayDecoratorService;
8
8
  init(): void;
9
- onReady(container: any): Promise<void>;
9
+ onReady(): Promise<void>;
10
10
  onServerReady(): Promise<void>;
11
11
  onStop(): Promise<void>;
12
12
  }
@@ -18,7 +18,11 @@ let EggConfiguration = class EggConfiguration {
18
18
  return (0, core_1.extractKoaLikeValue)(options.metadata.type, options.metadata.propertyData, options.originParamType)(options.originArgs[0], options.originArgs[1]);
19
19
  });
20
20
  }
21
- async onReady(container) { }
21
+ async onReady() {
22
+ // ps: 本想在这里清理掉egg添加的中间件,但是这里的数组已经只有一个 midway root middleware,其他的 getter 都是 egg 加进去的,但是不会被中间件执行,所以不需要清理
23
+ // 去掉为了 egg-socket.io 报错扫进去的 session
24
+ this.app.middleware = this.app.middleware.slice(0);
25
+ }
22
26
  async onServerReady() {
23
27
  // trigger server didReady
24
28
  this.app.messenger.emit('egg-ready');
@@ -72,16 +72,11 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
72
72
  await this.initSingleProcessEgg();
73
73
  }
74
74
  // insert error handler
75
- this.app.use(async (ctx, next) => {
75
+ const midwayRootMiddleware = async (ctx, next) => {
76
76
  // this.app.createAnonymousContext(ctx);
77
- const { result, error } = await (await this.getMiddleware())(ctx, next);
78
- if (error) {
79
- throw error;
80
- }
81
- if (result) {
82
- ctx.body = result;
83
- }
84
- });
77
+ await (await this.getMiddleware())(ctx, next);
78
+ };
79
+ this.app.use(midwayRootMiddleware);
85
80
  this.generator = new EggControllerGenerator(this.app, this.applicationContext, this.appLogger);
86
81
  this.overwriteApplication('app');
87
82
  await new Promise(resolve => {
@@ -90,7 +85,7 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
90
85
  resolve();
91
86
  });
92
87
  this.app.loader.loadOrigin();
93
- // hack use method
88
+ // 这里拦截 app.use 方法,让他可以加到 midway 的 middlewareManager 中
94
89
  this.app.originUse = this.app.use;
95
90
  this.app.use = this.app.useMiddleware;
96
91
  this.app.ready();
@@ -115,6 +110,13 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
115
110
  });
116
111
  debug(`[egg]: overwrite properties to "${processType}"`);
117
112
  this.defineApplicationProperties({
113
+ generateController: (controllerMapping) => {
114
+ const [controllerId, methodName] = controllerMapping.split('.');
115
+ return this.generator.generateController({
116
+ id: controllerId,
117
+ method: methodName,
118
+ });
119
+ },
118
120
  generateMiddleware: async (middlewareId) => {
119
121
  return this.generateMiddleware(middlewareId);
120
122
  },
@@ -134,17 +136,24 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
134
136
  }
135
137
  async loadMidwayController() {
136
138
  await this.generator.loadMidwayController(this.configurationOptions.globalPrefix, newRouter => {
137
- this.app.use(newRouter.middleware());
139
+ var _a;
140
+ const dispatchFn = newRouter.middleware();
141
+ dispatchFn._name = `midwayController(${((_a = newRouter === null || newRouter === void 0 ? void 0 : newRouter.opts) === null || _a === void 0 ? void 0 : _a.prefix) || '/'})`;
142
+ this.app.useMiddleware(dispatchFn);
138
143
  });
139
144
  }
140
145
  getFrameworkType() {
141
146
  return decorator_1.MidwayFrameworkType.WEB;
142
147
  }
143
148
  async run() {
149
+ var _a;
150
+ // move egg router to last
151
+ this.app.getMiddleware().findAndInsertLast('eggRouterMiddleware');
144
152
  // load controller
145
153
  await this.loadMidwayController();
146
154
  // restore use method
147
155
  this.app.use = this.app.originUse;
156
+ debug(`[egg]: current middleware = ${this.middlewareManager.getNames()}`);
148
157
  if (!this.isClusterMode) {
149
158
  // https config
150
159
  if (this.configurationOptions.key && this.configurationOptions.cert) {
@@ -173,17 +182,21 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
173
182
  // register httpServer to applicationContext
174
183
  this.getApplicationContext().registerObject(core_1.HTTP_SERVER_KEY, this.server);
175
184
  const eggConfig = this.configService.getConfiguration('egg');
176
- if (this.configService.getConfiguration('egg')) {
177
- new Promise(resolve => {
178
- const args = [eggConfig.port];
179
- if (eggConfig.hostname) {
180
- args.push(eggConfig.hostname);
181
- }
182
- args.push(() => {
183
- resolve();
185
+ if (!this.isClusterMode && eggConfig) {
186
+ const customPort = (_a = process.env.MIDWAY_HTTP_PORT) !== null && _a !== void 0 ? _a : eggConfig.port;
187
+ if (customPort) {
188
+ new Promise(resolve => {
189
+ const args = [customPort];
190
+ if (eggConfig.hostname) {
191
+ args.push(eggConfig.hostname);
192
+ }
193
+ args.push(() => {
194
+ resolve();
195
+ });
196
+ this.server.listen(...args);
197
+ process.env.MIDWAY_HTTP_PORT = String(customPort);
184
198
  });
185
- this.server.listen(...args);
186
- });
199
+ }
187
200
  }
188
201
  }
189
202
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/web",
3
- "version": "3.0.0-beta.5",
3
+ "version": "3.0.0-beta.9",
4
4
  "description": "Midway Web Framework for Egg.js",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  ],
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
- "@midwayjs/decorator": "^3.0.0-beta.5",
31
- "@midwayjs/mock": "^3.0.0-beta.5",
30
+ "@midwayjs/decorator": "^3.0.0-beta.9",
31
+ "@midwayjs/mock": "^3.0.0-beta.9",
32
32
  "dayjs": "^1.10.7",
33
33
  "egg-logger": "^2.4.2",
34
34
  "egg-mock": "^3.26.0",
@@ -43,8 +43,8 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@eggjs/router": "^2.0.0",
46
- "@midwayjs/core": "^3.0.0-beta.5",
47
- "@midwayjs/logger": "^3.0.0-beta.5",
46
+ "@midwayjs/core": "^3.0.0-beta.9",
47
+ "@midwayjs/logger": "^3.0.0-beta.9",
48
48
  "egg": "^2.28.0",
49
49
  "extend2": "^1.0.0",
50
50
  "find-up": "^5.0.0",
@@ -58,5 +58,5 @@
58
58
  "engines": {
59
59
  "node": ">=12"
60
60
  },
61
- "gitHead": "ab0bf05ae6d13f6435db2f7223202be61d585a1b"
61
+ "gitHead": "d23e4a4fee58097b98461625c428a37d55535cec"
62
62
  }