@midwayjs/express 3.20.4 → 4.0.0-beta.1
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/dist/config/config.default.d.ts +7 -2
- package/dist/config/config.default.js +25 -21
- package/dist/configuration.js +5 -5
- package/dist/framework.d.ts +1 -2
- package/dist/framework.js +10 -16
- package/dist/middlewareService.js +2 -2
- package/package.json +7 -7
- package/LICENSE +0 -21
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { Options, OptionsJson, OptionsText, OptionsUrlencoded } from 'body-parser';
|
|
2
2
|
import { CookieOptions } from 'express';
|
|
3
|
-
export declare const express: {
|
|
4
|
-
|
|
3
|
+
export declare const express: {};
|
|
4
|
+
export declare const midwayLogger: {
|
|
5
|
+
clients: {
|
|
6
|
+
appLogger: {
|
|
7
|
+
contextFormat: (info: any) => string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
5
10
|
};
|
|
6
11
|
export declare const cookieParser: {
|
|
7
12
|
enable?: boolean;
|
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.bodyParser = exports.cookieParser = exports.express = void 0;
|
|
4
|
-
exports.express = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
3
|
+
exports.bodyParser = exports.cookieParser = exports.midwayLogger = exports.express = void 0;
|
|
4
|
+
exports.express = {};
|
|
5
|
+
exports.midwayLogger = {
|
|
6
|
+
clients: {
|
|
7
|
+
appLogger: {
|
|
8
|
+
contextFormat: info => {
|
|
9
|
+
const req = info.ctx;
|
|
10
|
+
// format: '[$userId/$ip/$traceId/$use_ms $method $url]'
|
|
11
|
+
const userId = req?.['session']?.['userId'] || '-';
|
|
12
|
+
const traceId = req.traceId ?? '-';
|
|
13
|
+
const use = Date.now() - info.ctx.startTime;
|
|
14
|
+
const label = userId +
|
|
15
|
+
'/' +
|
|
16
|
+
req.ip +
|
|
17
|
+
'/' +
|
|
18
|
+
traceId +
|
|
19
|
+
'/' +
|
|
20
|
+
use +
|
|
21
|
+
'ms ' +
|
|
22
|
+
req.method +
|
|
23
|
+
' ' +
|
|
24
|
+
req.url;
|
|
25
|
+
return `${info.timestamp} ${info.LEVEL} ${info.pid} [${label}] ${info.message}`;
|
|
26
|
+
},
|
|
27
|
+
},
|
|
24
28
|
},
|
|
25
29
|
};
|
|
26
30
|
exports.cookieParser = {
|
package/dist/configuration.js
CHANGED
|
@@ -23,14 +23,14 @@ let ExpressConfiguration = class ExpressConfiguration {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
async onReady() {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const keys = this.configService.getConfiguration('express.keys') ??
|
|
27
|
+
this.configService.getConfiguration('keys');
|
|
28
28
|
const cookieParserConfig = this.configService.getConfiguration('cookieParser');
|
|
29
29
|
if (cookieParserConfig.enable) {
|
|
30
30
|
// add cookie parser middleware
|
|
31
31
|
this.expressFramework
|
|
32
32
|
.getMiddleware()
|
|
33
|
-
.insertFirst(cookieParser(
|
|
33
|
+
.insertFirst(cookieParser(cookieParserConfig.secret ?? keys, cookieParserConfig.options));
|
|
34
34
|
}
|
|
35
35
|
// add body parser
|
|
36
36
|
const bodyparserConfig = this.configService.getConfiguration('bodyParser');
|
|
@@ -52,6 +52,7 @@ let ExpressConfiguration = class ExpressConfiguration {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
|
+
exports.ExpressConfiguration = ExpressConfiguration;
|
|
55
56
|
__decorate([
|
|
56
57
|
(0, core_1.Inject)(),
|
|
57
58
|
__metadata("design:type", core_1.MidwayDecoratorService)
|
|
@@ -70,7 +71,7 @@ __decorate([
|
|
|
70
71
|
__metadata("design:paramtypes", []),
|
|
71
72
|
__metadata("design:returntype", void 0)
|
|
72
73
|
], ExpressConfiguration.prototype, "init", null);
|
|
73
|
-
ExpressConfiguration = __decorate([
|
|
74
|
+
exports.ExpressConfiguration = ExpressConfiguration = __decorate([
|
|
74
75
|
(0, core_1.Configuration)({
|
|
75
76
|
namespace: 'express',
|
|
76
77
|
imports: [session],
|
|
@@ -81,5 +82,4 @@ ExpressConfiguration = __decorate([
|
|
|
81
82
|
],
|
|
82
83
|
})
|
|
83
84
|
], ExpressConfiguration);
|
|
84
|
-
exports.ExpressConfiguration = ExpressConfiguration;
|
|
85
85
|
//# sourceMappingURL=configuration.js.map
|
package/dist/framework.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { BaseFramework, IMidwayBootstrapOptions, MiddlewareRespond,
|
|
2
|
+
import { BaseFramework, IMidwayBootstrapOptions, MiddlewareRespond, RouterInfo } from '@midwayjs/core';
|
|
3
3
|
import { IMidwayExpressApplication, IMidwayExpressConfigurationOptions, Context } from './interface';
|
|
4
4
|
import type { IRouter, IRouterHandler, Response, NextFunction } from 'express';
|
|
5
5
|
import { Server } from 'net';
|
|
@@ -11,7 +11,6 @@ export declare class MidwayExpressFramework extends BaseFramework<IMidwayExpress
|
|
|
11
11
|
configure(): IMidwayExpressConfigurationOptions;
|
|
12
12
|
applicationInitialize(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
|
|
13
13
|
run(): Promise<void>;
|
|
14
|
-
getFrameworkType(): MidwayFrameworkType;
|
|
15
14
|
/**
|
|
16
15
|
* wrap controller string to middleware function
|
|
17
16
|
*/
|
package/dist/framework.js
CHANGED
|
@@ -46,7 +46,6 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
46
46
|
this.app.use = this.app.useMiddleware;
|
|
47
47
|
}
|
|
48
48
|
async run() {
|
|
49
|
-
var _a;
|
|
50
49
|
debug(`[express]: use middlewares = "${this.getMiddleware().getNames()}"`);
|
|
51
50
|
// restore use method
|
|
52
51
|
this.app.use = this.app.originUse;
|
|
@@ -80,10 +79,9 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
80
79
|
this.filterManager
|
|
81
80
|
.runErrorFilter(err, req, res, next)
|
|
82
81
|
.then(data => {
|
|
83
|
-
var _a, _b;
|
|
84
82
|
const { result, error } = data;
|
|
85
83
|
if (error) {
|
|
86
|
-
const status =
|
|
84
|
+
const status = error.status ?? res.statusCode ?? 500;
|
|
87
85
|
// 5xx
|
|
88
86
|
if (status >= 500) {
|
|
89
87
|
try {
|
|
@@ -120,9 +118,9 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
120
118
|
};
|
|
121
119
|
// https config
|
|
122
120
|
if (serverOptions.key && serverOptions.cert) {
|
|
123
|
-
serverOptions.key = core_1.
|
|
124
|
-
serverOptions.cert = core_1.
|
|
125
|
-
serverOptions.ca = core_1.
|
|
121
|
+
serverOptions.key = core_1.PathFileUtils.getFileContentSync(serverOptions.key);
|
|
122
|
+
serverOptions.cert = core_1.PathFileUtils.getFileContentSync(serverOptions.cert);
|
|
123
|
+
serverOptions.ca = core_1.PathFileUtils.getFileContentSync(serverOptions.ca);
|
|
126
124
|
process.env.MIDWAY_HTTP_SSL = 'true';
|
|
127
125
|
if (serverOptions.http2) {
|
|
128
126
|
this.server = require('http2').createSecureServer(serverOptions, this.app);
|
|
@@ -141,7 +139,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
141
139
|
}
|
|
142
140
|
// register httpServer to applicationContext
|
|
143
141
|
this.applicationContext.registerObject(core_1.HTTP_SERVER_KEY, this.server);
|
|
144
|
-
const customPort =
|
|
142
|
+
const customPort = process.env.MIDWAY_HTTP_PORT ?? this.configurationOptions.port;
|
|
145
143
|
if (customPort) {
|
|
146
144
|
new Promise(resolve => {
|
|
147
145
|
const args = [customPort];
|
|
@@ -156,9 +154,6 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
156
154
|
});
|
|
157
155
|
}
|
|
158
156
|
}
|
|
159
|
-
getFrameworkType() {
|
|
160
|
-
return core_1.MidwayFrameworkType.WEB_EXPRESS;
|
|
161
|
-
}
|
|
162
157
|
/**
|
|
163
158
|
* wrap controller string to middleware function
|
|
164
159
|
*/
|
|
@@ -215,7 +210,6 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
215
210
|
});
|
|
216
211
|
}
|
|
217
212
|
async loadMidwayController() {
|
|
218
|
-
var _a, _b;
|
|
219
213
|
this.webRouterService = await this.applicationContext.getAsync(core_1.MidwayWebRouterService, [
|
|
220
214
|
{
|
|
221
215
|
globalPrefix: this.configurationOptions.globalPrefix,
|
|
@@ -230,7 +224,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
230
224
|
this.logger.debug(`Load Controller "${routerInfo.controllerId}", prefix=${routerInfo.prefix}`);
|
|
231
225
|
// new router
|
|
232
226
|
const newRouter = this.createRouter(routerInfo.routerOptions);
|
|
233
|
-
routerInfo.middleware =
|
|
227
|
+
routerInfo.middleware = routerInfo.middleware ?? [];
|
|
234
228
|
// add router middleware
|
|
235
229
|
if (routerInfo.middleware.length) {
|
|
236
230
|
const routerMiddlewareFn = await this.expressMiddlewareService.compose(routerInfo.middleware, this.app);
|
|
@@ -241,7 +235,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
241
235
|
for (const routeInfo of routes) {
|
|
242
236
|
const routeMiddlewareList = [];
|
|
243
237
|
// routeInfo middleware
|
|
244
|
-
routeInfo.middleware =
|
|
238
|
+
routeInfo.middleware = routeInfo.middleware ?? [];
|
|
245
239
|
if (routeInfo.middleware.length) {
|
|
246
240
|
const routeMiddlewareFn = await this.expressMiddlewareService.compose(routeInfo.middleware, this.app);
|
|
247
241
|
routeMiddlewareList.push(routeMiddlewareFn);
|
|
@@ -287,11 +281,11 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
287
281
|
return process.env.MIDWAY_HTTP_PORT;
|
|
288
282
|
}
|
|
289
283
|
getFrameworkName() {
|
|
290
|
-
return '
|
|
284
|
+
return 'express';
|
|
291
285
|
}
|
|
292
286
|
};
|
|
293
|
-
MidwayExpressFramework =
|
|
287
|
+
exports.MidwayExpressFramework = MidwayExpressFramework;
|
|
288
|
+
exports.MidwayExpressFramework = MidwayExpressFramework = __decorate([
|
|
294
289
|
(0, core_1.Framework)()
|
|
295
290
|
], MidwayExpressFramework);
|
|
296
|
-
exports.MidwayExpressFramework = MidwayExpressFramework;
|
|
297
291
|
//# sourceMappingURL=framework.js.map
|
|
@@ -117,12 +117,12 @@ let MidwayExpressMiddlewareService = class MidwayExpressMiddlewareService {
|
|
|
117
117
|
return composeFn;
|
|
118
118
|
}
|
|
119
119
|
};
|
|
120
|
-
MidwayExpressMiddlewareService =
|
|
120
|
+
exports.MidwayExpressMiddlewareService = MidwayExpressMiddlewareService;
|
|
121
|
+
exports.MidwayExpressMiddlewareService = MidwayExpressMiddlewareService = __decorate([
|
|
121
122
|
(0, core_1.Provide)(),
|
|
122
123
|
(0, core_1.Scope)(core_1.ScopeEnum.Singleton),
|
|
123
124
|
__metadata("design:paramtypes", [Object])
|
|
124
125
|
], MidwayExpressMiddlewareService);
|
|
125
|
-
exports.MidwayExpressMiddlewareService = MidwayExpressMiddlewareService;
|
|
126
126
|
function wrapMiddleware(mw, options) {
|
|
127
127
|
// support options.enable
|
|
128
128
|
if (options.enable === false)
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/express",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-beta.1",
|
|
4
4
|
"description": "Midway Web Framework for Express",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"test": "node
|
|
10
|
-
"cov": "node
|
|
9
|
+
"test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
|
|
10
|
+
"cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
|
|
11
11
|
"ci": "npm run test"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@midwayjs/
|
|
27
|
+
"@midwayjs/core": "^4.0.0-beta.1",
|
|
28
|
+
"@midwayjs/mock": "^4.0.0-beta.1",
|
|
28
29
|
"@types/body-parser": "1.19.5",
|
|
29
30
|
"@types/express": "4.17.21",
|
|
30
31
|
"fs-extra": "11.3.0"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@midwayjs/
|
|
34
|
-
"@midwayjs/express-session": "^3.20.4",
|
|
34
|
+
"@midwayjs/express-session": "^4.0.0-beta.1",
|
|
35
35
|
"body-parser": "1.20.3",
|
|
36
36
|
"cookie-parser": "^1.4.6",
|
|
37
37
|
"express": "4.21.2"
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=12"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "832961ec3aff123c033197d8c00cb2bc9bad7ff8"
|
|
48
48
|
}
|
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.
|