@midwayjs/express 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,45 @@
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/express
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
+ * typeorm EntityView missing connectionName ([#1403](https://github.com/midwayjs/midway/issues/1403)) ([30b2b37](https://github.com/midwayjs/midway/commit/30b2b3711db485cb85d825d56aeabf53b1374cae))
21
+
22
+
23
+
24
+
25
+
26
+ # [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
27
+
28
+ **Note:** Version bump only for package @midwayjs/express
29
+
30
+
31
+
32
+
33
+
34
+ # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
35
+
36
+
37
+ ### Bug Fixes
38
+
39
+ * class transformer method missing ([#1387](https://github.com/midwayjs/midway/issues/1387)) ([074e839](https://github.com/midwayjs/midway/commit/074e8393598dc95e2742f735df75a2191c5fe25d))
40
+
41
+
42
+
43
+
44
+
6
45
  # [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
46
 
8
47
  **Note:** Version bump only for package @midwayjs/express
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/dist/framework.js CHANGED
@@ -5,9 +5,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
8
  Object.defineProperty(exports, "__esModule", { value: true });
12
9
  exports.MidwayExpressFramework = void 0;
13
10
  const core_1 = require("@midwayjs/core");
@@ -20,6 +17,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
20
17
  return this.configService.getConfiguration('express');
21
18
  }
22
19
  async applicationInitialize(options) {
20
+ this.expressMiddlewareService = await this.applicationContext.getAsync(middlewareService_1.MidwayExpressMiddlewareService, [this.applicationContext]);
23
21
  this.app = express();
24
22
  this.app.use((req, res, next) => {
25
23
  const ctx = req;
@@ -31,6 +29,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
31
29
  });
32
30
  }
33
31
  async run() {
32
+ var _a;
34
33
  // use global middleware
35
34
  const globalMiddleware = await this.getMiddleware();
36
35
  this.app.use(globalMiddleware);
@@ -70,7 +69,8 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
70
69
  }
71
70
  // register httpServer to applicationContext
72
71
  this.applicationContext.registerObject(core_1.HTTP_SERVER_KEY, this.server);
73
- if (this.configurationOptions.port) {
72
+ const customPort = (_a = process.env.MIDWAY_HTTP_PORT) !== null && _a !== void 0 ? _a : this.configurationOptions.port;
73
+ if (customPort) {
74
74
  new Promise(resolve => {
75
75
  const args = [this.configurationOptions.port];
76
76
  if (this.configurationOptions.hostname) {
@@ -80,6 +80,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
80
80
  resolve();
81
81
  });
82
82
  this.server.listen(...args);
83
+ process.env.MIDWAY_HTTP_PORT = String(customPort);
83
84
  });
84
85
  }
85
86
  }
@@ -146,13 +147,14 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
146
147
  // add route
147
148
  const routes = routerTable.get(routerInfo.prefix);
148
149
  for (const routeInfo of routes) {
150
+ const routeMiddlewareList = [];
149
151
  // router middleware
150
152
  await this.handlerWebMiddleware(routeInfo.middleware, middlewareImpl => {
151
- newRouter.use(middlewareImpl);
153
+ routeMiddlewareList.push(middlewareImpl);
152
154
  });
153
155
  this.logger.debug(`Load Router "${routeInfo.requestMethod.toUpperCase()} ${routeInfo.url}"`);
154
156
  // apply controller from request context
155
- newRouter[routeInfo.requestMethod].call(newRouter, routeInfo.url, this.generateController(routeInfo));
157
+ newRouter[routeInfo.requestMethod].call(newRouter, routeInfo.url, ...routeMiddlewareList, this.generateController(routeInfo));
156
158
  }
157
159
  this.app.use(routerInfo.prefix, newRouter);
158
160
  }
@@ -187,10 +189,6 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
187
189
  return logger_1.MidwayExpressContextLogger;
188
190
  }
189
191
  };
190
- __decorate([
191
- (0, decorator_1.Inject)(),
192
- __metadata("design:type", middlewareService_1.MidwayExpressMiddlewareService)
193
- ], MidwayExpressFramework.prototype, "expressMiddlewareService", void 0);
194
192
  MidwayExpressFramework = __decorate([
195
193
  (0, decorator_1.Framework)()
196
194
  ], MidwayExpressFramework);
@@ -2,6 +2,10 @@
2
2
  import { CommonMiddlewareUnion, ContextMiddlewareManager, IConfigurationOptions, IMiddleware, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
3
3
  import { Application as ExpressApplication, NextFunction as ExpressNextFunction, Request, Response } from 'express';
4
4
  export declare type IMidwayExpressContext = IMidwayContext<Request>;
5
+ /**
6
+ * @deprecated use IMidwayExpressContext
7
+ */
8
+ export declare type IMidwayExpressRequest = IMidwayExpressContext;
5
9
  export declare type IMidwayExpressMiddleware = IMiddleware<IMidwayExpressContext, Response, ExpressNextFunction>;
6
10
  export interface IMidwayExpressApplication extends IMidwayApplication<IMidwayExpressContext, ExpressApplication> {
7
11
  /**
@@ -1,4 +1,4 @@
1
- import { IMidwayContainer, CommonMiddleware } from '@midwayjs/core';
1
+ import { IMidwayContainer, CommonMiddleware, FunctionMiddleware } from '@midwayjs/core';
2
2
  import { IMidwayExpressContext } from './interface';
3
3
  import { NextFunction, Response } from 'express';
4
4
  export declare class MidwayExpressMiddlewareService {
@@ -9,5 +9,5 @@ export declare class MidwayExpressMiddlewareService {
9
9
  _name: string;
10
10
  }>;
11
11
  }
12
- export declare function pathMatching(options: any): (ctx?: any) => any;
12
+ export declare function wrapMiddleware(mw: FunctionMiddleware<any, any, any>, options: any): (context: any, next: any, options?: any) => any;
13
13
  //# sourceMappingURL=middlewareService.d.ts.map
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.pathMatching = exports.MidwayExpressMiddlewareService = void 0;
12
+ exports.wrapMiddleware = exports.MidwayExpressMiddlewareService = void 0;
13
13
  const decorator_1 = require("@midwayjs/decorator");
14
14
  const core_1 = require("@midwayjs/core");
15
15
  let MidwayExpressMiddlewareService = class MidwayExpressMiddlewareService {
@@ -38,7 +38,7 @@ let MidwayExpressMiddlewareService = class MidwayExpressMiddlewareService {
38
38
  else {
39
39
  // wrap ignore and match
40
40
  const mw = fn;
41
- const match = pathMatching({
41
+ const match = (0, core_1.pathMatching)({
42
42
  match: classMiddleware.match,
43
43
  ignore: classMiddleware.ignore,
44
44
  });
@@ -79,41 +79,21 @@ MidwayExpressMiddlewareService = __decorate([
79
79
  __metadata("design:paramtypes", [Object])
80
80
  ], MidwayExpressMiddlewareService);
81
81
  exports.MidwayExpressMiddlewareService = MidwayExpressMiddlewareService;
82
- function pathMatching(options) {
83
- options = options || {};
84
- if (options.match && options.ignore)
85
- throw new core_1.MidwayCommonError('options.match and options.ignore can not both present');
82
+ function wrapMiddleware(mw, options) {
83
+ // support options.enable
84
+ if (options.enable === false)
85
+ return null;
86
+ // support options.match and options.ignore
86
87
  if (!options.match && !options.ignore)
87
- return () => true;
88
- const matchFn = options.match
89
- ? toPathMatch(options.match)
90
- : toPathMatch(options.ignore);
91
- return function pathMatch(ctx) {
92
- const matched = matchFn(ctx);
93
- return options.match ? matched : !matched;
88
+ return mw;
89
+ const match = (0, core_1.pathMatching)(options);
90
+ const fn = (req, res, next) => {
91
+ if (!match(req))
92
+ return next();
93
+ return mw(req, res, next);
94
94
  };
95
+ fn._name = mw._name + 'middlewareWrapper';
96
+ return fn;
95
97
  }
96
- exports.pathMatching = pathMatching;
97
- function toPathMatch(pattern) {
98
- if (typeof pattern === 'string') {
99
- const reg = (0, core_1.pathToRegexp)(pattern, [], { end: false });
100
- if (reg.global)
101
- reg.lastIndex = 0;
102
- return ctx => reg.test(ctx.path);
103
- }
104
- if (pattern instanceof RegExp) {
105
- return ctx => {
106
- if (pattern.global)
107
- pattern.lastIndex = 0;
108
- return pattern.test(ctx.path);
109
- };
110
- }
111
- if (typeof pattern === 'function')
112
- return pattern;
113
- if (Array.isArray(pattern)) {
114
- const matchs = pattern.map(item => toPathMatch(item));
115
- return ctx => matchs.some(match => match(ctx));
116
- }
117
- throw new core_1.MidwayCommonError('match/ignore pattern must be RegExp, Array or String, but got ' + pattern);
118
- }
98
+ exports.wrapMiddleware = wrapMiddleware;
119
99
  //# sourceMappingURL=middlewareService.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/express",
3
- "version": "3.0.0-beta.5",
3
+ "version": "3.0.0-beta.9",
4
4
  "description": "Midway Web Framework for Express",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -23,14 +23,14 @@
23
23
  ],
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@midwayjs/decorator": "^3.0.0-beta.5",
27
- "@midwayjs/mock": "^3.0.0-beta.5",
26
+ "@midwayjs/decorator": "^3.0.0-beta.9",
27
+ "@midwayjs/mock": "^3.0.0-beta.9",
28
28
  "@types/express": "^4.17.8",
29
29
  "fs-extra": "^8.0.1"
30
30
  },
31
31
  "dependencies": {
32
- "@midwayjs/core": "^3.0.0-beta.5",
33
- "@midwayjs/logger": "^3.0.0-beta.5",
32
+ "@midwayjs/core": "^3.0.0-beta.9",
33
+ "@midwayjs/logger": "^3.0.0-beta.9",
34
34
  "express": "^4.17.1"
35
35
  },
36
36
  "author": "Harry Chen <czy88840616@gmail.com>",
@@ -41,5 +41,5 @@
41
41
  "engines": {
42
42
  "node": ">=12"
43
43
  },
44
- "gitHead": "ab0bf05ae6d13f6435db2f7223202be61d585a1b"
44
+ "gitHead": "d23e4a4fee58097b98461625c428a37d55535cec"
45
45
  }