@midwayjs/express 3.0.0-beta.7 → 3.0.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/README.md +3 -3
- package/dist/config/config.default.d.ts +22 -0
- package/dist/config/config.default.js +27 -0
- package/dist/configuration.d.ts +4 -1
- package/dist/configuration.js +46 -1
- package/dist/framework.d.ts +8 -5
- package/dist/framework.js +90 -34
- package/dist/interface.d.ts +39 -9
- package/dist/logger.d.ts +2 -2
- package/dist/middlewareService.d.ts +6 -5
- package/dist/middlewareService.js +65 -45
- package/dist/util.d.ts +2 -0
- package/dist/util.js +13 -0
- package/package.json +15 -11
- package/CHANGELOG.md +0 -973
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# midway
|
|
1
|
+
# midway for express
|
|
2
2
|
|
|
3
|
-
[](http://packagequality.com/#?package=@midwayjs/express)
|
|
4
4
|
[](https://github.com/midwayjs/midway/pulls)
|
|
5
5
|
|
|
6
6
|
this is a sub package for midway.
|
|
7
7
|
|
|
8
|
-
Document: [https://midwayjs.org
|
|
8
|
+
Document: [https://midwayjs.org](https://midwayjs.org)
|
|
9
9
|
|
|
10
10
|
## License
|
|
11
11
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Options, OptionsJson, OptionsText, OptionsUrlencoded } from 'body-parser';
|
|
2
|
+
import { CookieOptions } from 'express';
|
|
3
|
+
export declare const cookieParser: {
|
|
4
|
+
secret?: string | string[];
|
|
5
|
+
options?: CookieOptions;
|
|
6
|
+
};
|
|
7
|
+
export declare const bodyParser: {
|
|
8
|
+
enable?: boolean;
|
|
9
|
+
json?: OptionsJson & {
|
|
10
|
+
enable?: boolean;
|
|
11
|
+
};
|
|
12
|
+
raw?: Options & {
|
|
13
|
+
enable?: boolean;
|
|
14
|
+
};
|
|
15
|
+
text?: OptionsText & {
|
|
16
|
+
enable?: boolean;
|
|
17
|
+
};
|
|
18
|
+
urlencoded?: OptionsUrlencoded & {
|
|
19
|
+
enable?: boolean;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=config.default.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bodyParser = exports.cookieParser = void 0;
|
|
4
|
+
exports.cookieParser = {};
|
|
5
|
+
exports.bodyParser = {
|
|
6
|
+
enable: true,
|
|
7
|
+
json: {
|
|
8
|
+
enable: true,
|
|
9
|
+
limit: '1mb',
|
|
10
|
+
strict: true,
|
|
11
|
+
},
|
|
12
|
+
raw: {
|
|
13
|
+
enable: false,
|
|
14
|
+
limit: '1mb',
|
|
15
|
+
},
|
|
16
|
+
text: {
|
|
17
|
+
enable: true,
|
|
18
|
+
limit: '1mb',
|
|
19
|
+
},
|
|
20
|
+
urlencoded: {
|
|
21
|
+
enable: true,
|
|
22
|
+
extended: false,
|
|
23
|
+
limit: '1mb',
|
|
24
|
+
parameterLimit: 1000,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=config.default.js.map
|
package/dist/configuration.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { MidwayDecoratorService } from '@midwayjs/core';
|
|
1
|
+
import { MidwayConfigService, MidwayDecoratorService } from '@midwayjs/core';
|
|
2
|
+
import { MidwayExpressFramework } from './framework';
|
|
2
3
|
export declare class ExpressConfiguration {
|
|
3
4
|
decoratorService: MidwayDecoratorService;
|
|
5
|
+
expressFramework: MidwayExpressFramework;
|
|
6
|
+
configService: MidwayConfigService;
|
|
4
7
|
init(): void;
|
|
5
8
|
onReady(): Promise<void>;
|
|
6
9
|
}
|
package/dist/configuration.js
CHANGED
|
@@ -12,18 +12,57 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.ExpressConfiguration = void 0;
|
|
13
13
|
const decorator_1 = require("@midwayjs/decorator");
|
|
14
14
|
const core_1 = require("@midwayjs/core");
|
|
15
|
+
const session = require("@midwayjs/express-session");
|
|
16
|
+
const framework_1 = require("./framework");
|
|
17
|
+
const bodyParser = require("body-parser");
|
|
18
|
+
const cookieParser = require("cookie-parser");
|
|
19
|
+
const DefaultConfig = require("./config/config.default");
|
|
15
20
|
let ExpressConfiguration = class ExpressConfiguration {
|
|
16
21
|
init() {
|
|
17
22
|
this.decoratorService.registerParameterHandler(decorator_1.WEB_ROUTER_PARAM_KEY, options => {
|
|
18
23
|
return (0, core_1.extractExpressLikeValue)(options.metadata.type, options.metadata.propertyData, options.originParamType)(options.originArgs[0], options.originArgs[1], options.originArgs[2]);
|
|
19
24
|
});
|
|
20
25
|
}
|
|
21
|
-
async onReady() {
|
|
26
|
+
async onReady() {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
const keys = (_a = this.configService.getConfiguration('express.keys')) !== null && _a !== void 0 ? _a : this.configService.getConfiguration('keys');
|
|
29
|
+
const cookieParserConfig = this.configService.getConfiguration('cookieParser');
|
|
30
|
+
// add cookie parser middleware
|
|
31
|
+
this.expressFramework
|
|
32
|
+
.getMiddleware()
|
|
33
|
+
.insertFirst(cookieParser((_b = cookieParserConfig.secret) !== null && _b !== void 0 ? _b : keys, cookieParserConfig.options));
|
|
34
|
+
// add body parser
|
|
35
|
+
const bodyparserConfig = this.configService.getConfiguration('bodyParser');
|
|
36
|
+
if (bodyparserConfig.enable) {
|
|
37
|
+
// create application/json parser
|
|
38
|
+
if (bodyparserConfig.json.enable) {
|
|
39
|
+
this.expressFramework.useMiddleware(bodyParser.json(bodyparserConfig.json));
|
|
40
|
+
}
|
|
41
|
+
if (bodyparserConfig.raw.enable) {
|
|
42
|
+
this.expressFramework.useMiddleware(bodyParser.raw(bodyparserConfig.raw));
|
|
43
|
+
}
|
|
44
|
+
if (bodyparserConfig.text.enable) {
|
|
45
|
+
this.expressFramework.useMiddleware(bodyParser.text(bodyparserConfig.text));
|
|
46
|
+
}
|
|
47
|
+
// create application/x-www-form-urlencoded parser
|
|
48
|
+
if (bodyparserConfig.urlencoded.enable) {
|
|
49
|
+
this.expressFramework.useMiddleware(bodyParser.urlencoded(bodyparserConfig.urlencoded));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
22
53
|
};
|
|
23
54
|
__decorate([
|
|
24
55
|
(0, decorator_1.Inject)(),
|
|
25
56
|
__metadata("design:type", core_1.MidwayDecoratorService)
|
|
26
57
|
], ExpressConfiguration.prototype, "decoratorService", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
(0, decorator_1.Inject)(),
|
|
60
|
+
__metadata("design:type", framework_1.MidwayExpressFramework)
|
|
61
|
+
], ExpressConfiguration.prototype, "expressFramework", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
(0, decorator_1.Inject)(),
|
|
64
|
+
__metadata("design:type", core_1.MidwayConfigService)
|
|
65
|
+
], ExpressConfiguration.prototype, "configService", void 0);
|
|
27
66
|
__decorate([
|
|
28
67
|
(0, decorator_1.Init)(),
|
|
29
68
|
__metadata("design:type", Function),
|
|
@@ -33,6 +72,12 @@ __decorate([
|
|
|
33
72
|
ExpressConfiguration = __decorate([
|
|
34
73
|
(0, decorator_1.Configuration)({
|
|
35
74
|
namespace: 'express',
|
|
75
|
+
imports: [session],
|
|
76
|
+
importConfigs: [
|
|
77
|
+
{
|
|
78
|
+
default: DefaultConfig,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
36
81
|
})
|
|
37
82
|
], ExpressConfiguration);
|
|
38
83
|
exports.ExpressConfiguration = ExpressConfiguration;
|
package/dist/framework.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { BaseFramework, IMidwayBootstrapOptions, MiddlewareRespond, MidwayFrameworkType, RouterInfo } from '@midwayjs/core';
|
|
3
|
-
import { IMidwayExpressApplication, IMidwayExpressConfigurationOptions,
|
|
3
|
+
import { IMidwayExpressApplication, IMidwayExpressConfigurationOptions, Context } from './interface';
|
|
4
4
|
import type { IRouter, IRouterHandler, Response, NextFunction } from 'express';
|
|
5
5
|
import { Server } from 'net';
|
|
6
6
|
import { MidwayExpressContextLogger } from './logger';
|
|
7
|
-
export declare class MidwayExpressFramework extends BaseFramework<IMidwayExpressApplication,
|
|
7
|
+
export declare class MidwayExpressFramework extends BaseFramework<IMidwayExpressApplication, Context, IMidwayExpressConfigurationOptions, Response, NextFunction> {
|
|
8
8
|
app: IMidwayExpressApplication;
|
|
9
9
|
private server;
|
|
10
10
|
private expressMiddlewareService;
|
|
@@ -16,17 +16,20 @@ 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<
|
|
19
|
+
loadMidwayController(): Promise<Array<{
|
|
20
|
+
prefix: string;
|
|
21
|
+
middleware: any;
|
|
22
|
+
}>>;
|
|
20
23
|
/**
|
|
21
24
|
* @param routerOptions
|
|
22
25
|
*/
|
|
23
26
|
protected createRouter(routerOptions: {
|
|
24
27
|
sensitive: any;
|
|
25
28
|
}): IRouter;
|
|
26
|
-
|
|
27
|
-
getMiddleware<Response, NextFunction>(): Promise<MiddlewareRespond<IMidwayExpressContext, Response, NextFunction>>;
|
|
29
|
+
applyMiddleware<Response, NextFunction>(): Promise<MiddlewareRespond<Context, Response, NextFunction>>;
|
|
28
30
|
beforeStop(): Promise<void>;
|
|
29
31
|
getServer(): Server;
|
|
32
|
+
getPort(): string;
|
|
30
33
|
getFrameworkName(): string;
|
|
31
34
|
getDefaultContextLoggerClass(): typeof MidwayExpressContextLogger;
|
|
32
35
|
}
|
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");
|
|
@@ -15,12 +12,19 @@ const decorator_1 = require("@midwayjs/decorator");
|
|
|
15
12
|
const express = require("express");
|
|
16
13
|
const logger_1 = require("./logger");
|
|
17
14
|
const middlewareService_1 = require("./middlewareService");
|
|
15
|
+
const util_1 = require("util");
|
|
16
|
+
const util_2 = require("./util");
|
|
17
|
+
const debug = (0, util_1.debuglog)('midway:debug');
|
|
18
18
|
let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFramework {
|
|
19
19
|
configure() {
|
|
20
20
|
return this.configService.getConfiguration('express');
|
|
21
21
|
}
|
|
22
22
|
async applicationInitialize(options) {
|
|
23
|
+
this.expressMiddlewareService = await this.applicationContext.getAsync(middlewareService_1.MidwayExpressMiddlewareService, [this.applicationContext]);
|
|
24
|
+
debug('[express]: create express app');
|
|
23
25
|
this.app = express();
|
|
26
|
+
debug('[express]: use root middleware');
|
|
27
|
+
// use root middleware
|
|
24
28
|
this.app.use((req, res, next) => {
|
|
25
29
|
const ctx = req;
|
|
26
30
|
this.app.createAnonymousContext(ctx);
|
|
@@ -29,25 +33,71 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
29
33
|
ctx.requestContext.registerObject('res', res);
|
|
30
34
|
next();
|
|
31
35
|
});
|
|
36
|
+
this.defineApplicationProperties();
|
|
37
|
+
// hack use method
|
|
38
|
+
this.app.originUse = this.app.use;
|
|
39
|
+
this.app.use = this.app.useMiddleware;
|
|
32
40
|
}
|
|
33
41
|
async run() {
|
|
34
42
|
var _a;
|
|
43
|
+
debug(`[express]: use middlewares = "${this.getMiddleware().getNames()}"`);
|
|
44
|
+
// restore use method
|
|
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();
|
|
35
49
|
// use global middleware
|
|
36
|
-
const globalMiddleware = await this.
|
|
50
|
+
const globalMiddleware = await this.applyMiddleware();
|
|
51
|
+
debug('[express]: use and apply all framework and global middleware');
|
|
37
52
|
this.app.use(globalMiddleware);
|
|
38
|
-
// load
|
|
39
|
-
|
|
53
|
+
// load router after global middleware
|
|
54
|
+
for (const info of routerMiddlewares) {
|
|
55
|
+
this.app.use(info.prefix, info.middleware);
|
|
56
|
+
}
|
|
57
|
+
debug('[express]: use 404 not found middleware');
|
|
58
|
+
// eslint-disable-next-line
|
|
59
|
+
this.app.use(function notFound(req, res, next) {
|
|
60
|
+
next(new core_1.httpError.NotFoundError());
|
|
61
|
+
});
|
|
62
|
+
debug('[express]: use global error handler middleware');
|
|
40
63
|
// use global error handler
|
|
41
|
-
this.app.use(
|
|
42
|
-
|
|
43
|
-
|
|
64
|
+
this.app.use((err, req, res, next) => {
|
|
65
|
+
this.filterManager
|
|
66
|
+
.runErrorFilter(err, req, res, next)
|
|
67
|
+
.then(data => {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
const { result, error } = data;
|
|
44
70
|
if (error) {
|
|
71
|
+
const status = (_b = (_a = error.status) !== null && _a !== void 0 ? _a : res.statusCode) !== null && _b !== void 0 ? _b : 500;
|
|
72
|
+
// 5xx
|
|
73
|
+
if (status >= 500) {
|
|
74
|
+
try {
|
|
75
|
+
req.logger.error(err);
|
|
76
|
+
}
|
|
77
|
+
catch (ex) {
|
|
78
|
+
this.logger.error(err);
|
|
79
|
+
this.logger.error(ex);
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// 4xx
|
|
84
|
+
try {
|
|
85
|
+
req.logger.warn(err);
|
|
86
|
+
}
|
|
87
|
+
catch (ex) {
|
|
88
|
+
this.logger.warn(err);
|
|
89
|
+
this.logger.error(ex);
|
|
90
|
+
}
|
|
91
|
+
res.status(status);
|
|
45
92
|
next(error);
|
|
46
93
|
}
|
|
47
94
|
else {
|
|
48
|
-
|
|
95
|
+
(0, util_2.sendData)(res, result);
|
|
49
96
|
}
|
|
50
|
-
}
|
|
97
|
+
})
|
|
98
|
+
.catch(err => {
|
|
99
|
+
next(err);
|
|
100
|
+
});
|
|
51
101
|
});
|
|
52
102
|
// https config
|
|
53
103
|
if (this.configurationOptions.key && this.configurationOptions.cert) {
|
|
@@ -74,7 +124,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
74
124
|
const customPort = (_a = process.env.MIDWAY_HTTP_PORT) !== null && _a !== void 0 ? _a : this.configurationOptions.port;
|
|
75
125
|
if (customPort) {
|
|
76
126
|
new Promise(resolve => {
|
|
77
|
-
const args = [
|
|
127
|
+
const args = [customPort];
|
|
78
128
|
if (this.configurationOptions.hostname) {
|
|
79
129
|
args.push(this.configurationOptions.hostname);
|
|
80
130
|
}
|
|
@@ -93,7 +143,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
93
143
|
* wrap controller string to middleware function
|
|
94
144
|
*/
|
|
95
145
|
generateController(routeInfo) {
|
|
96
|
-
return async (req, res, next) => {
|
|
146
|
+
return (0, middlewareService_1.wrapAsyncHandler)(async (req, res, next) => {
|
|
97
147
|
const controller = await req.requestContext.getAsync(routeInfo.id);
|
|
98
148
|
const result = await controller[routeInfo.method].call(controller, req, res, next);
|
|
99
149
|
if (res.headersSent) {
|
|
@@ -127,38 +177,49 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
127
177
|
if (error) {
|
|
128
178
|
throw error;
|
|
129
179
|
}
|
|
130
|
-
|
|
131
|
-
};
|
|
180
|
+
(0, util_2.sendData)(res, returnValue);
|
|
181
|
+
});
|
|
132
182
|
}
|
|
133
183
|
async loadMidwayController() {
|
|
184
|
+
var _a, _b;
|
|
134
185
|
const collector = new core_1.WebRouterCollector('', {
|
|
135
186
|
globalPrefix: this.configurationOptions.globalPrefix,
|
|
136
187
|
});
|
|
137
188
|
const routerTable = await collector.getRouterTable();
|
|
138
189
|
const routerList = await collector.getRoutePriorityList();
|
|
190
|
+
const routerMiddlewares = [];
|
|
139
191
|
for (const routerInfo of routerList) {
|
|
140
192
|
// bind controller first
|
|
141
193
|
this.getApplicationContext().bindClass(routerInfo.routerModule);
|
|
142
194
|
this.logger.debug(`Load Controller "${routerInfo.controllerId}", prefix=${routerInfo.prefix}`);
|
|
143
195
|
// new router
|
|
144
196
|
const newRouter = this.createRouter(routerInfo.routerOptions);
|
|
197
|
+
routerInfo.middleware = (_a = routerInfo.middleware) !== null && _a !== void 0 ? _a : [];
|
|
145
198
|
// add router middleware
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
199
|
+
if (routerInfo.middleware.length) {
|
|
200
|
+
const routerMiddlewareFn = await this.expressMiddlewareService.compose(routerInfo.middleware, this.app);
|
|
201
|
+
newRouter.use(routerMiddlewareFn);
|
|
202
|
+
}
|
|
149
203
|
// add route
|
|
150
204
|
const routes = routerTable.get(routerInfo.prefix);
|
|
151
205
|
for (const routeInfo of routes) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
206
|
+
const routeMiddlewareList = [];
|
|
207
|
+
// routeInfo middleware
|
|
208
|
+
routeInfo.middleware = (_b = routeInfo.middleware) !== null && _b !== void 0 ? _b : [];
|
|
209
|
+
if (routeInfo.middleware.length) {
|
|
210
|
+
const routeMiddlewareFn = await this.expressMiddlewareService.compose(routeInfo.middleware, this.app);
|
|
211
|
+
routeMiddlewareList.push(routeMiddlewareFn);
|
|
212
|
+
}
|
|
156
213
|
this.logger.debug(`Load Router "${routeInfo.requestMethod.toUpperCase()} ${routeInfo.url}"`);
|
|
157
214
|
// apply controller from request context
|
|
158
|
-
newRouter[routeInfo.requestMethod].call(newRouter, routeInfo.url, this.generateController(routeInfo));
|
|
215
|
+
newRouter[routeInfo.requestMethod].call(newRouter, routeInfo.url, ...routeMiddlewareList, this.generateController(routeInfo));
|
|
159
216
|
}
|
|
160
|
-
|
|
217
|
+
routerMiddlewares.push({
|
|
218
|
+
prefix: routerInfo.prefix,
|
|
219
|
+
middleware: newRouter,
|
|
220
|
+
});
|
|
161
221
|
}
|
|
222
|
+
return routerMiddlewares;
|
|
162
223
|
}
|
|
163
224
|
/**
|
|
164
225
|
* @param routerOptions
|
|
@@ -166,13 +227,9 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
166
227
|
createRouter(routerOptions) {
|
|
167
228
|
return express.Router({ caseSensitive: routerOptions.sensitive });
|
|
168
229
|
}
|
|
169
|
-
async
|
|
170
|
-
const fn = await this.expressMiddlewareService.compose(middlewares);
|
|
171
|
-
handlerCallback(fn);
|
|
172
|
-
}
|
|
173
|
-
async getMiddleware() {
|
|
230
|
+
async applyMiddleware() {
|
|
174
231
|
if (!this.composeMiddleware) {
|
|
175
|
-
this.composeMiddleware = await this.expressMiddlewareService.compose(this.middlewareManager);
|
|
232
|
+
this.composeMiddleware = await this.expressMiddlewareService.compose(this.middlewareManager, this.app);
|
|
176
233
|
await this.filterManager.init(this.applicationContext);
|
|
177
234
|
}
|
|
178
235
|
return this.composeMiddleware;
|
|
@@ -183,6 +240,9 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
183
240
|
getServer() {
|
|
184
241
|
return this.server;
|
|
185
242
|
}
|
|
243
|
+
getPort() {
|
|
244
|
+
return process.env.MIDWAY_HTTP_PORT;
|
|
245
|
+
}
|
|
186
246
|
getFrameworkName() {
|
|
187
247
|
return 'midway:express';
|
|
188
248
|
}
|
|
@@ -190,10 +250,6 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
190
250
|
return logger_1.MidwayExpressContextLogger;
|
|
191
251
|
}
|
|
192
252
|
};
|
|
193
|
-
__decorate([
|
|
194
|
-
(0, decorator_1.Inject)(),
|
|
195
|
-
__metadata("design:type", middlewareService_1.MidwayExpressMiddlewareService)
|
|
196
|
-
], MidwayExpressFramework.prototype, "expressMiddlewareService", void 0);
|
|
197
253
|
MidwayExpressFramework = __decorate([
|
|
198
254
|
(0, decorator_1.Framework)()
|
|
199
255
|
], MidwayExpressFramework);
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { CommonMiddlewareUnion, ContextMiddlewareManager, IConfigurationOptions, IMiddleware, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
|
|
3
|
-
import { Application as ExpressApplication, NextFunction as ExpressNextFunction, Request, Response } from 'express';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
3
|
+
import { Application as ExpressApplication, NextFunction as ExpressNextFunction, Request as ExpressRequest, Response as ExpressResponse } from 'express';
|
|
4
|
+
import { Options, OptionsJson, OptionsText, OptionsUrlencoded } from 'body-parser';
|
|
5
|
+
declare type Request = IMidwayContext<ExpressRequest>;
|
|
6
|
+
export declare type Response = ExpressResponse;
|
|
7
|
+
export declare type NextFunction = ExpressNextFunction;
|
|
8
|
+
export interface Context extends Request {
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated use Context
|
|
12
|
+
*/
|
|
13
|
+
export declare type IMidwayExpressRequest = Context;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated use Context
|
|
16
|
+
*/
|
|
17
|
+
export declare type IMidwayExpressContext = Context;
|
|
18
|
+
export declare type IMidwayExpressMiddleware = IMiddleware<Context, ExpressResponse, ExpressNextFunction>;
|
|
19
|
+
export interface IMidwayExpressApplication extends IMidwayApplication<Context, ExpressApplication> {
|
|
7
20
|
/**
|
|
8
21
|
* add global middleware to app
|
|
9
22
|
* @param Middleware
|
|
10
23
|
*/
|
|
11
|
-
useMiddleware<Response, NextFunction>(Middleware: CommonMiddlewareUnion<
|
|
24
|
+
useMiddleware<Response, NextFunction>(Middleware: CommonMiddlewareUnion<Context, Response, NextFunction>): void;
|
|
12
25
|
/**
|
|
13
26
|
* get global middleware
|
|
14
27
|
*/
|
|
15
|
-
getMiddleware<Response, NextFunction>(): ContextMiddlewareManager<
|
|
28
|
+
getMiddleware<Response, NextFunction>(): ContextMiddlewareManager<Context, Response, NextFunction>;
|
|
16
29
|
}
|
|
17
30
|
export interface IMidwayExpressConfigurationOptions extends IConfigurationOptions {
|
|
31
|
+
/**
|
|
32
|
+
* session or cookie secret key
|
|
33
|
+
*/
|
|
34
|
+
keys?: string | string[];
|
|
18
35
|
/**
|
|
19
36
|
* application http port
|
|
20
37
|
*/
|
|
@@ -45,12 +62,25 @@ export interface IMidwayExpressConfigurationOptions extends IConfigurationOption
|
|
|
45
62
|
globalPrefix?: string;
|
|
46
63
|
}
|
|
47
64
|
export declare type Application = IMidwayExpressApplication;
|
|
48
|
-
export declare type NextFunction = ExpressNextFunction;
|
|
49
|
-
export interface Context extends IMidwayExpressContext {
|
|
50
|
-
}
|
|
51
65
|
declare module '@midwayjs/core/dist/interface' {
|
|
52
66
|
interface MidwayConfig {
|
|
53
67
|
express?: IMidwayExpressConfigurationOptions;
|
|
68
|
+
bodyParser?: {
|
|
69
|
+
enable?: boolean;
|
|
70
|
+
json?: OptionsJson & {
|
|
71
|
+
enable?: boolean;
|
|
72
|
+
};
|
|
73
|
+
raw?: Options & {
|
|
74
|
+
enable?: boolean;
|
|
75
|
+
};
|
|
76
|
+
text?: OptionsText & {
|
|
77
|
+
enable?: boolean;
|
|
78
|
+
};
|
|
79
|
+
urlencoded?: OptionsUrlencoded & {
|
|
80
|
+
enable?: boolean;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
54
83
|
}
|
|
55
84
|
}
|
|
85
|
+
export {};
|
|
56
86
|
//# sourceMappingURL=interface.d.ts.map
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MidwayContextLogger } from '@midwayjs/logger';
|
|
2
|
-
import {
|
|
3
|
-
export declare class MidwayExpressContextLogger extends MidwayContextLogger<
|
|
2
|
+
import { Context } from './interface';
|
|
3
|
+
export declare class MidwayExpressContextLogger extends MidwayContextLogger<Context> {
|
|
4
4
|
formatContextLabel(): string;
|
|
5
5
|
}
|
|
6
6
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { IMidwayContainer, CommonMiddleware } from '@midwayjs/core';
|
|
2
|
-
import {
|
|
1
|
+
import { IMidwayContainer, CommonMiddleware, FunctionMiddleware } from '@midwayjs/core';
|
|
2
|
+
import { Context, Application } from './interface';
|
|
3
3
|
import { NextFunction, Response } from 'express';
|
|
4
|
+
export declare function wrapAsyncHandler(fn: any): any;
|
|
4
5
|
export declare class MidwayExpressMiddlewareService {
|
|
5
6
|
readonly applicationContext: IMidwayContainer;
|
|
6
7
|
constructor(applicationContext: IMidwayContainer);
|
|
7
|
-
compose(middleware: Array<CommonMiddleware<
|
|
8
|
-
(req:
|
|
8
|
+
compose(middleware: Array<CommonMiddleware<Context, Response, NextFunction> | string>, app: Application, name?: string): Promise<{
|
|
9
|
+
(req: Context, res: Response, nextFunction: NextFunction): any;
|
|
9
10
|
_name: string;
|
|
10
11
|
}>;
|
|
11
12
|
}
|
|
12
|
-
export declare function
|
|
13
|
+
export declare function wrapMiddleware(mw: FunctionMiddleware<any, any, any>, options: any): (context: any, next: any, options?: any) => any;
|
|
13
14
|
//# sourceMappingURL=middlewareService.d.ts.map
|