@midwayjs/express 3.0.11 → 3.1.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/framework.d.ts +1 -0
- package/dist/framework.js +13 -1
- package/dist/index.js +5 -1
- package/dist/interface.d.ts +9 -3
- package/package.json +5 -5
package/dist/framework.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export declare class MidwayExpressFramework extends BaseFramework<IMidwayExpress
|
|
|
25
25
|
protected createRouter(routerOptions: {
|
|
26
26
|
sensitive: any;
|
|
27
27
|
}): IRouter;
|
|
28
|
+
useRouterMiddleware(routerPath: string, middleware: any): void;
|
|
28
29
|
applyMiddleware<Response, NextFunction>(): Promise<MiddlewareRespond<Context, Response, NextFunction>>;
|
|
29
30
|
beforeStop(): Promise<void>;
|
|
30
31
|
getServer(): Server;
|
package/dist/framework.js
CHANGED
|
@@ -32,7 +32,16 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
32
32
|
ctx.requestContext.registerObject('res', res);
|
|
33
33
|
next();
|
|
34
34
|
});
|
|
35
|
-
this.defineApplicationProperties(
|
|
35
|
+
this.defineApplicationProperties({
|
|
36
|
+
useMiddleware: (routerPath, ...middleware) => {
|
|
37
|
+
if (typeof routerPath === 'string' && middleware) {
|
|
38
|
+
return this.useRouterMiddleware(routerPath, middleware);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return this.useMiddleware(routerPath);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
});
|
|
36
45
|
// hack use method
|
|
37
46
|
this.app.originUse = this.app.use;
|
|
38
47
|
this.app.use = this.app.useMiddleware;
|
|
@@ -226,6 +235,9 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
226
235
|
createRouter(routerOptions) {
|
|
227
236
|
return express.Router({ caseSensitive: routerOptions.sensitive });
|
|
228
237
|
}
|
|
238
|
+
useRouterMiddleware(routerPath, middleware) {
|
|
239
|
+
this.app.originUse(routerPath, ...middleware);
|
|
240
|
+
}
|
|
229
241
|
async applyMiddleware() {
|
|
230
242
|
if (!this.composeMiddleware) {
|
|
231
243
|
this.composeMiddleware = await this.expressMiddlewareService.compose(this.middlewareManager, this.app);
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { CommonMiddlewareUnion, ContextMiddlewareManager, IConfigurationOptions, IMiddleware, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
|
|
2
|
+
import { CommonMiddlewareUnion, ContextMiddlewareManager, FunctionMiddleware, IConfigurationOptions, IMiddleware, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
|
|
3
3
|
import { Application as ExpressApplication, CookieOptions, NextFunction as ExpressNextFunction, Request as ExpressRequest, Response as ExpressResponse } from 'express';
|
|
4
4
|
import { Options, OptionsJson, OptionsText, OptionsUrlencoded } from 'body-parser';
|
|
5
5
|
declare type Request = IMidwayContext<ExpressRequest>;
|
|
@@ -17,11 +17,17 @@ export declare type IMidwayExpressRequest = Context;
|
|
|
17
17
|
export declare type IMidwayExpressContext = Context;
|
|
18
18
|
export declare type IMidwayExpressMiddleware = IMiddleware<Context, ExpressResponse, ExpressNextFunction>;
|
|
19
19
|
export interface IMidwayExpressApplication extends IMidwayApplication<Context, ExpressApplication> {
|
|
20
|
+
/**
|
|
21
|
+
* mount router and middleware
|
|
22
|
+
* @param routerPath
|
|
23
|
+
* @param middleware
|
|
24
|
+
*/
|
|
25
|
+
useMiddleware<Response, NextFunction>(routerPath: string, ...middleware: FunctionMiddleware<Context, Response, NextFunction>[]): void;
|
|
20
26
|
/**
|
|
21
27
|
* add global middleware to app
|
|
22
|
-
* @param
|
|
28
|
+
* @param middleware
|
|
23
29
|
*/
|
|
24
|
-
useMiddleware<Response, NextFunction>(
|
|
30
|
+
useMiddleware<Response, NextFunction>(middleware: CommonMiddlewareUnion<Context, Response, NextFunction>): void;
|
|
25
31
|
/**
|
|
26
32
|
* get global middleware
|
|
27
33
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/express",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Midway Web Framework for Express",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@midwayjs/decorator": "^3.0.10",
|
|
27
27
|
"@midwayjs/logger": "^2.15.0",
|
|
28
|
-
"@midwayjs/mock": "^3.
|
|
28
|
+
"@midwayjs/mock": "^3.1.1",
|
|
29
29
|
"@types/body-parser": "1.19.2",
|
|
30
30
|
"@types/express": "4.17.13",
|
|
31
31
|
"fs-extra": "10.0.1"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@midwayjs/core": "^3.
|
|
35
|
-
"@midwayjs/express-session": "^3.
|
|
34
|
+
"@midwayjs/core": "^3.1.1",
|
|
35
|
+
"@midwayjs/express-session": "^3.1.1",
|
|
36
36
|
"body-parser": "1.19.2",
|
|
37
37
|
"cookie-parser": "^1.4.6",
|
|
38
38
|
"express": "4.17.3"
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=12"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "b7a5c817d2316b93967367c34cff20a98b1ce4b7"
|
|
49
49
|
}
|