@midwayjs/express 3.4.0-beta.1 → 3.4.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2013 - Now midwayjs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -7,6 +7,7 @@ export declare class MidwayExpressFramework extends BaseFramework<IMidwayExpress
7
7
  app: IMidwayExpressApplication;
8
8
  private server;
9
9
  private expressMiddlewareService;
10
+ private webRouterService;
10
11
  configure(): IMidwayExpressConfigurationOptions;
11
12
  applicationInitialize(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
12
13
  run(): Promise<void>;
package/dist/framework.js CHANGED
@@ -160,8 +160,14 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
160
160
  */
161
161
  generateController(routeInfo) {
162
162
  return (0, middlewareService_1.wrapAsyncHandler)(async (req, res, next) => {
163
- const controller = await req.requestContext.getAsync(routeInfo.id);
164
- const result = await controller[routeInfo.method].call(controller, req, res, next);
163
+ let result;
164
+ if (typeof routeInfo.method !== 'string') {
165
+ result = await routeInfo.method(req, res, next);
166
+ }
167
+ else {
168
+ const controller = await req.requestContext.getAsync(routeInfo.id);
169
+ result = await controller[routeInfo.method].call(controller, req, res, next);
170
+ }
165
171
  if (res.headersSent) {
166
172
  // return when response send
167
173
  return;
@@ -198,11 +204,13 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
198
204
  }
199
205
  async loadMidwayController() {
200
206
  var _a, _b;
201
- const collector = new core_1.WebRouterCollector('', {
202
- globalPrefix: this.configurationOptions.globalPrefix,
203
- });
204
- const routerTable = await collector.getRouterTable();
205
- const routerList = await collector.getRoutePriorityList();
207
+ this.webRouterService = await this.applicationContext.getAsync(core_1.MidwayWebRouterService, [
208
+ {
209
+ globalPrefix: this.configurationOptions.globalPrefix,
210
+ },
211
+ ]);
212
+ const routerTable = await this.webRouterService.getRouterTable();
213
+ const routerList = await this.webRouterService.getRoutePriorityList();
206
214
  const routerMiddlewares = [];
207
215
  for (const routerInfo of routerList) {
208
216
  // bind controller first
@@ -254,7 +262,11 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
254
262
  return this.composeMiddleware;
255
263
  }
256
264
  async beforeStop() {
257
- this.server.close();
265
+ if (this.server) {
266
+ new Promise(resolve => {
267
+ this.server.close(resolve);
268
+ });
269
+ }
258
270
  }
259
271
  getServer() {
260
272
  return this.server;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/express",
3
- "version": "3.4.0-beta.1",
3
+ "version": "3.4.0-beta.12",
4
4
  "description": "Midway Web Framework for Express",
5
5
  "main": "dist/index",
6
6
  "typings": "index.d.ts",
@@ -24,19 +24,19 @@
24
24
  ],
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
- "@midwayjs/decorator": "^3.4.0-beta.1",
27
+ "@midwayjs/decorator": "^3.4.0-beta.12",
28
28
  "@midwayjs/logger": "^2.15.0",
29
- "@midwayjs/mock": "^3.4.0-beta.1",
29
+ "@midwayjs/mock": "^3.4.0-beta.12",
30
30
  "@types/body-parser": "1.19.2",
31
31
  "@types/express": "4.17.13",
32
32
  "fs-extra": "10.0.1"
33
33
  },
34
34
  "dependencies": {
35
- "@midwayjs/core": "^3.4.0-beta.1",
36
- "@midwayjs/express-session": "^3.4.0-beta.1",
37
- "body-parser": "1.19.2",
35
+ "@midwayjs/core": "^3.4.0-beta.12",
36
+ "@midwayjs/express-session": "^3.4.0-beta.12",
37
+ "body-parser": "1.20.0",
38
38
  "cookie-parser": "^1.4.6",
39
- "express": "4.17.3"
39
+ "express": "4.18.1"
40
40
  },
41
41
  "author": "Harry Chen <czy88840616@gmail.com>",
42
42
  "repository": {
@@ -46,5 +46,5 @@
46
46
  "engines": {
47
47
  "node": ">=12"
48
48
  },
49
- "gitHead": "a603d2348d6141f8f723901498f03a162a037708"
49
+ "gitHead": "cb639763ececfc7928221eaafbd515bfd93c6ca1"
50
50
  }