@midwayjs/express 3.0.0-beta.7 → 3.0.0-beta.8
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 +12 -0
- package/README.md +1 -1
- package/dist/framework.js +4 -9
- package/dist/interface.d.ts +4 -0
- package/dist/middlewareService.d.ts +2 -2
- package/dist/middlewareService.js +16 -36
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
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.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* 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))
|
|
12
|
+
* typeorm EntityView missing connectionName ([#1403](https://github.com/midwayjs/midway/issues/1403)) ([30b2b37](https://github.com/midwayjs/midway/commit/30b2b3711db485cb85d825d56aeabf53b1374cae))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
6
18
|
# [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
|
|
7
19
|
|
|
8
20
|
**Note:** Version bump only for package @midwayjs/express
|
package/README.md
CHANGED
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;
|
|
@@ -149,13 +147,14 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
149
147
|
// add route
|
|
150
148
|
const routes = routerTable.get(routerInfo.prefix);
|
|
151
149
|
for (const routeInfo of routes) {
|
|
150
|
+
const routeMiddlewareList = [];
|
|
152
151
|
// router middleware
|
|
153
152
|
await this.handlerWebMiddleware(routeInfo.middleware, middlewareImpl => {
|
|
154
|
-
|
|
153
|
+
routeMiddlewareList.push(middlewareImpl);
|
|
155
154
|
});
|
|
156
155
|
this.logger.debug(`Load Router "${routeInfo.requestMethod.toUpperCase()} ${routeInfo.url}"`);
|
|
157
156
|
// apply controller from request context
|
|
158
|
-
newRouter[routeInfo.requestMethod].call(newRouter, routeInfo.url, this.generateController(routeInfo));
|
|
157
|
+
newRouter[routeInfo.requestMethod].call(newRouter, routeInfo.url, ...routeMiddlewareList, this.generateController(routeInfo));
|
|
159
158
|
}
|
|
160
159
|
this.app.use(routerInfo.prefix, newRouter);
|
|
161
160
|
}
|
|
@@ -190,10 +189,6 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
190
189
|
return logger_1.MidwayExpressContextLogger;
|
|
191
190
|
}
|
|
192
191
|
};
|
|
193
|
-
__decorate([
|
|
194
|
-
(0, decorator_1.Inject)(),
|
|
195
|
-
__metadata("design:type", middlewareService_1.MidwayExpressMiddlewareService)
|
|
196
|
-
], MidwayExpressFramework.prototype, "expressMiddlewareService", void 0);
|
|
197
192
|
MidwayExpressFramework = __decorate([
|
|
198
193
|
(0, decorator_1.Framework)()
|
|
199
194
|
], MidwayExpressFramework);
|
package/dist/interface.d.ts
CHANGED
|
@@ -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
|
|
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.
|
|
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
|
|
83
|
-
|
|
84
|
-
if (options.
|
|
85
|
-
|
|
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
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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.
|
|
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.
|
|
3
|
+
"version": "3.0.0-beta.8",
|
|
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.
|
|
27
|
-
"@midwayjs/mock": "^3.0.0-beta.
|
|
26
|
+
"@midwayjs/decorator": "^3.0.0-beta.8",
|
|
27
|
+
"@midwayjs/mock": "^3.0.0-beta.8",
|
|
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.
|
|
33
|
-
"@midwayjs/logger": "^3.0.0-beta.
|
|
32
|
+
"@midwayjs/core": "^3.0.0-beta.8",
|
|
33
|
+
"@midwayjs/logger": "^3.0.0-beta.8",
|
|
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": "
|
|
44
|
+
"gitHead": "bfafbdf8798f48d4daac5dd88ad53c6b2f33c110"
|
|
45
45
|
}
|