@midwayjs/express 3.0.0-beta.14 → 3.0.0-beta.15

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,23 @@
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.15](https://github.com/midwayjs/midway/compare/v3.0.0-beta.14...v3.0.0-beta.15) (2022-01-07)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * serverless app run ([#1523](https://github.com/midwayjs/midway/issues/1523)) ([5a25eb7](https://github.com/midwayjs/midway/commit/5a25eb7ebb17bf9b0e2ba4feee5bc1649f70d56f))
12
+
13
+
14
+ ### Features
15
+
16
+ * add info middleware ([#1530](https://github.com/midwayjs/midway/issues/1530)) ([7077f1d](https://github.com/midwayjs/midway/commit/7077f1d84355633a1c2fced35bfcc2152f42a7ac))
17
+ * add secret filter ([#1531](https://github.com/midwayjs/midway/issues/1531)) ([ce77e48](https://github.com/midwayjs/midway/commit/ce77e4804aaffc18a0a091d3726e36d7ec1514b2))
18
+
19
+
20
+
21
+
22
+
6
23
  # [3.0.0-beta.14](https://github.com/midwayjs/midway/compare/v3.0.0-beta.13...v3.0.0-beta.14) (2022-01-04)
7
24
 
8
25
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # midway-web
1
+ # midway for express
2
2
 
3
- [![Package Quality](http://npm.packagequality.com/shield/midway-web.svg)](http://packagequality.com/#?package=midway-web)
3
+ [![Package Quality](http://npm.packagequality.com/shield/@midwayjs/express.svg)](http://packagequality.com/#?package=@midwayjs/express)
4
4
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/midwayjs/midway/pulls)
5
5
 
6
6
  this is a sub package for midway.
@@ -16,7 +16,10 @@ export declare class MidwayExpressFramework extends BaseFramework<IMidwayExpress
16
16
  * wrap controller string to middleware function
17
17
  */
18
18
  protected generateController(routeInfo: RouterInfo): IRouterHandler<any>;
19
- loadMidwayController(): Promise<void>;
19
+ loadMidwayController(): Promise<Array<{
20
+ prefix: string;
21
+ middleware: any;
22
+ }>>;
20
23
  /**
21
24
  * @param routerOptions
22
25
  */
@@ -28,6 +31,5 @@ export declare class MidwayExpressFramework extends BaseFramework<IMidwayExpress
28
31
  getServer(): Server;
29
32
  getFrameworkName(): string;
30
33
  getDefaultContextLoggerClass(): typeof MidwayExpressContextLogger;
31
- protected sendData(res: any, data: any): void;
32
34
  }
33
35
  //# sourceMappingURL=framework.d.ts.map
package/dist/framework.js CHANGED
@@ -13,6 +13,7 @@ const express = require("express");
13
13
  const logger_1 = require("./logger");
14
14
  const middlewareService_1 = require("./middlewareService");
15
15
  const util_1 = require("util");
16
+ const util_2 = require("./util");
16
17
  const debug = (0, util_1.debuglog)('midway:debug');
17
18
  let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFramework {
18
19
  configure() {
@@ -42,13 +43,17 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
42
43
  debug(`[express]: use middlewares = "${this.getMiddleware().getNames()}"`);
43
44
  // restore use method
44
45
  this.app.use = this.app.originUse;
46
+ debug('[express]: use user router middleware');
47
+ // load controller,must apply router filter here
48
+ const routerMiddlewares = await this.loadMidwayController();
45
49
  // use global middleware
46
50
  const globalMiddleware = await this.applyMiddleware();
47
51
  debug('[express]: use and apply all framework and global middleware');
48
52
  this.app.use(globalMiddleware);
49
- debug('[express]: use user router middleware');
50
- // load controller
51
- await this.loadMidwayController();
53
+ // load router after global middleware
54
+ for (const info of routerMiddlewares) {
55
+ this.app.use(info.prefix, info.middleware);
56
+ }
52
57
  debug('[express]: use 404 not found middleware');
53
58
  // eslint-disable-next-line
54
59
  this.app.use(function notFound(req, res, next) {
@@ -87,7 +92,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
87
92
  next(error);
88
93
  }
89
94
  else {
90
- this.sendData(res, result);
95
+ (0, util_2.sendData)(res, result);
91
96
  }
92
97
  })
93
98
  .catch(err => {
@@ -172,7 +177,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
172
177
  if (error) {
173
178
  throw error;
174
179
  }
175
- this.sendData(res, returnValue);
180
+ (0, util_2.sendData)(res, returnValue);
176
181
  });
177
182
  }
178
183
  async loadMidwayController() {
@@ -182,6 +187,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
182
187
  });
183
188
  const routerTable = await collector.getRouterTable();
184
189
  const routerList = await collector.getRoutePriorityList();
190
+ const routerMiddlewares = [];
185
191
  for (const routerInfo of routerList) {
186
192
  // bind controller first
187
193
  this.getApplicationContext().bindClass(routerInfo.routerModule);
@@ -208,8 +214,12 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
208
214
  // apply controller from request context
209
215
  newRouter[routeInfo.requestMethod].call(newRouter, routeInfo.url, ...routeMiddlewareList, this.generateController(routeInfo));
210
216
  }
211
- this.app.use(routerInfo.prefix, newRouter);
217
+ routerMiddlewares.push({
218
+ prefix: routerInfo.prefix,
219
+ middleware: newRouter,
220
+ });
212
221
  }
222
+ return routerMiddlewares;
213
223
  }
214
224
  /**
215
225
  * @param routerOptions
@@ -236,14 +246,6 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
236
246
  getDefaultContextLoggerClass() {
237
247
  return logger_1.MidwayExpressContextLogger;
238
248
  }
239
- sendData(res, data) {
240
- if (typeof data === 'number') {
241
- res.status(res.statusCode).send('' + data);
242
- }
243
- else {
244
- res.status(res.statusCode).send(data);
245
- }
246
- }
247
249
  };
248
250
  MidwayExpressFramework = __decorate([
249
251
  (0, decorator_1.Framework)()
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.wrapMiddleware = exports.MidwayExpressMiddlewareService = exports.wrapAsyncHandler = void 0;
13
13
  const decorator_1 = require("@midwayjs/decorator");
14
14
  const core_1 = require("@midwayjs/core");
15
+ const util_1 = require("./util");
15
16
  function wrapAsyncHandler(fn) {
16
17
  if ((0, decorator_1.isAsyncFunction)(fn)) {
17
18
  return (req, res, next) => {
@@ -91,7 +92,11 @@ let MidwayExpressMiddlewareService = class MidwayExpressMiddlewareService {
91
92
  return dispatch(pos + 1, err);
92
93
  }
93
94
  try {
94
- return handler(req, res, next);
95
+ Promise.resolve(handler(req, res, next)).then(result => {
96
+ if (result) {
97
+ (0, util_1.sendData)(res, result);
98
+ }
99
+ });
95
100
  }
96
101
  catch (err) {
97
102
  // Avoid future errors that could diverge stack execution.
package/dist/util.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function sendData(res: any, data: any): void;
2
+ //# sourceMappingURL=util.d.ts.map
package/dist/util.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendData = void 0;
4
+ function sendData(res, data) {
5
+ if (typeof data === 'number') {
6
+ res.status(res.statusCode).send('' + data);
7
+ }
8
+ else {
9
+ res.status(res.statusCode).send(data);
10
+ }
11
+ }
12
+ exports.sendData = sendData;
13
+ //# sourceMappingURL=util.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/express",
3
- "version": "3.0.0-beta.14",
3
+ "version": "3.0.0-beta.15",
4
4
  "description": "Midway Web Framework for Express",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -23,16 +23,16 @@
23
23
  ],
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@midwayjs/decorator": "^3.0.0-beta.14",
26
+ "@midwayjs/decorator": "^3.0.0-beta.15",
27
27
  "@midwayjs/logger": "2.14.0",
28
- "@midwayjs/mock": "^3.0.0-beta.14",
28
+ "@midwayjs/mock": "^3.0.0-beta.15",
29
29
  "@types/body-parser": "1.19.2",
30
30
  "@types/express": "4.17.13",
31
31
  "fs-extra": "10.0.0"
32
32
  },
33
33
  "dependencies": {
34
- "@midwayjs/core": "^3.0.0-beta.14",
35
- "@midwayjs/express-session": "^3.0.0-beta.14",
34
+ "@midwayjs/core": "^3.0.0-beta.15",
35
+ "@midwayjs/express-session": "^3.0.0-beta.15",
36
36
  "body-parser": "1.19.1",
37
37
  "cookie-parser": "^1.4.6",
38
38
  "express": "4.17.2"
@@ -45,5 +45,5 @@
45
45
  "engines": {
46
46
  "node": ">=12"
47
47
  },
48
- "gitHead": "95695ada36190cf376e93a1a8866b3fb6dde06bc"
48
+ "gitHead": "6b9778557289d9e8b562c7ce6127736db1248973"
49
49
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
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.