@midwayjs/express 3.0.0-beta.16 → 3.0.0-beta.17
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 +4 -3
- package/dist/framework.js +3 -0
- package/dist/interface.d.ts +17 -11
- package/dist/logger.d.ts +2 -2
- package/dist/middlewareService.d.ts +3 -3
- package/dist/middlewareService.js +3 -3
- package/package.json +8 -8
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;
|
|
@@ -26,9 +26,10 @@ export declare class MidwayExpressFramework extends BaseFramework<IMidwayExpress
|
|
|
26
26
|
protected createRouter(routerOptions: {
|
|
27
27
|
sensitive: any;
|
|
28
28
|
}): IRouter;
|
|
29
|
-
applyMiddleware<Response, NextFunction>(): Promise<MiddlewareRespond<
|
|
29
|
+
applyMiddleware<Response, NextFunction>(): Promise<MiddlewareRespond<Context, Response, NextFunction>>;
|
|
30
30
|
beforeStop(): Promise<void>;
|
|
31
31
|
getServer(): Server;
|
|
32
|
+
getPort(): string;
|
|
32
33
|
getFrameworkName(): string;
|
|
33
34
|
getDefaultContextLoggerClass(): typeof MidwayExpressContextLogger;
|
|
34
35
|
}
|
package/dist/framework.js
CHANGED
|
@@ -240,6 +240,9 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
|
|
|
240
240
|
getServer() {
|
|
241
241
|
return this.server;
|
|
242
242
|
}
|
|
243
|
+
getPort() {
|
|
244
|
+
return process.env.MIDWAY_HTTP_PORT;
|
|
245
|
+
}
|
|
243
246
|
getFrameworkName() {
|
|
244
247
|
return 'midway:express';
|
|
245
248
|
}
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
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';
|
|
3
|
+
import { Application as ExpressApplication, 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>;
|
|
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;
|
|
6
14
|
/**
|
|
7
|
-
* @deprecated use
|
|
15
|
+
* @deprecated use Context
|
|
8
16
|
*/
|
|
9
|
-
export declare type
|
|
10
|
-
export declare type IMidwayExpressMiddleware = IMiddleware<
|
|
11
|
-
export interface IMidwayExpressApplication extends IMidwayApplication<
|
|
17
|
+
export declare type IMidwayExpressContext = Context;
|
|
18
|
+
export declare type IMidwayExpressMiddleware = IMiddleware<Context, ExpressResponse, ExpressNextFunction>;
|
|
19
|
+
export interface IMidwayExpressApplication extends IMidwayApplication<Context, ExpressApplication> {
|
|
12
20
|
/**
|
|
13
21
|
* add global middleware to app
|
|
14
22
|
* @param Middleware
|
|
15
23
|
*/
|
|
16
|
-
useMiddleware<Response, NextFunction>(Middleware: CommonMiddlewareUnion<
|
|
24
|
+
useMiddleware<Response, NextFunction>(Middleware: CommonMiddlewareUnion<Context, Response, NextFunction>): void;
|
|
17
25
|
/**
|
|
18
26
|
* get global middleware
|
|
19
27
|
*/
|
|
20
|
-
getMiddleware<Response, NextFunction>(): ContextMiddlewareManager<
|
|
28
|
+
getMiddleware<Response, NextFunction>(): ContextMiddlewareManager<Context, Response, NextFunction>;
|
|
21
29
|
}
|
|
22
30
|
export interface IMidwayExpressConfigurationOptions extends IConfigurationOptions {
|
|
23
31
|
/**
|
|
@@ -54,9 +62,6 @@ export interface IMidwayExpressConfigurationOptions extends IConfigurationOption
|
|
|
54
62
|
globalPrefix?: string;
|
|
55
63
|
}
|
|
56
64
|
export declare type Application = IMidwayExpressApplication;
|
|
57
|
-
export declare type NextFunction = ExpressNextFunction;
|
|
58
|
-
export interface Context extends IMidwayExpressContext {
|
|
59
|
-
}
|
|
60
65
|
declare module '@midwayjs/core/dist/interface' {
|
|
61
66
|
interface MidwayConfig {
|
|
62
67
|
express?: IMidwayExpressConfigurationOptions;
|
|
@@ -77,4 +82,5 @@ declare module '@midwayjs/core/dist/interface' {
|
|
|
77
82
|
};
|
|
78
83
|
}
|
|
79
84
|
}
|
|
85
|
+
export {};
|
|
80
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,12 +1,12 @@
|
|
|
1
1
|
import { IMidwayContainer, CommonMiddleware, FunctionMiddleware } from '@midwayjs/core';
|
|
2
|
-
import {
|
|
2
|
+
import { Context, Application } from './interface';
|
|
3
3
|
import { NextFunction, Response } from 'express';
|
|
4
4
|
export declare function wrapAsyncHandler(fn: any): any;
|
|
5
5
|
export declare class MidwayExpressMiddlewareService {
|
|
6
6
|
readonly applicationContext: IMidwayContainer;
|
|
7
7
|
constructor(applicationContext: IMidwayContainer);
|
|
8
|
-
compose(middleware: Array<CommonMiddleware<
|
|
9
|
-
(req:
|
|
8
|
+
compose(middleware: Array<CommonMiddleware<Context, Response, NextFunction> | string>, app: Application, name?: string): Promise<{
|
|
9
|
+
(req: Context, res: Response, nextFunction: NextFunction): any;
|
|
10
10
|
_name: string;
|
|
11
11
|
}>;
|
|
12
12
|
}
|
|
@@ -14,7 +14,7 @@ const decorator_1 = require("@midwayjs/decorator");
|
|
|
14
14
|
const core_1 = require("@midwayjs/core");
|
|
15
15
|
const util_1 = require("./util");
|
|
16
16
|
function wrapAsyncHandler(fn) {
|
|
17
|
-
if (decorator_1.
|
|
17
|
+
if (decorator_1.Types.isAsyncFunction(fn)) {
|
|
18
18
|
return (req, res, next) => {
|
|
19
19
|
return fn(req, res, next).catch(err => {
|
|
20
20
|
next(err);
|
|
@@ -36,14 +36,14 @@ let MidwayExpressMiddlewareService = class MidwayExpressMiddlewareService {
|
|
|
36
36
|
}
|
|
37
37
|
const newMiddlewareArr = [];
|
|
38
38
|
for (let fn of middleware) {
|
|
39
|
-
if (decorator_1.
|
|
39
|
+
if (decorator_1.Types.isClass(fn) || typeof fn === 'string') {
|
|
40
40
|
if (typeof fn === 'string' &&
|
|
41
41
|
!this.applicationContext.hasDefinition(fn)) {
|
|
42
42
|
throw new core_1.MidwayCommonError('Middleware definition not found in midway container');
|
|
43
43
|
}
|
|
44
44
|
const classMiddleware = await this.applicationContext.getAsync(fn);
|
|
45
45
|
if (classMiddleware) {
|
|
46
|
-
fn = classMiddleware.resolve(app);
|
|
46
|
+
fn = await classMiddleware.resolve(app);
|
|
47
47
|
// wrap async middleware
|
|
48
48
|
fn = wrapAsyncHandler(fn);
|
|
49
49
|
if (!classMiddleware.match && !classMiddleware.ignore) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/express",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.17",
|
|
4
4
|
"description": "Midway Web Framework for Express",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"test": "node --require=ts-node/register ../../node_modules/.bin/jest",
|
|
10
|
-
"cov": "node --require=ts-node/register ../../node_modules/.bin/jest --coverage --forceExit",
|
|
9
|
+
"test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
|
|
10
|
+
"cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit",
|
|
11
11
|
"ci": "npm run test"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
],
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@midwayjs/decorator": "^3.0.0-beta.
|
|
26
|
+
"@midwayjs/decorator": "^3.0.0-beta.17",
|
|
27
27
|
"@midwayjs/logger": "2.14.0",
|
|
28
|
-
"@midwayjs/mock": "^3.0.0-beta.
|
|
28
|
+
"@midwayjs/mock": "^3.0.0-beta.17",
|
|
29
29
|
"@types/body-parser": "1.19.2",
|
|
30
30
|
"@types/express": "4.17.13",
|
|
31
31
|
"fs-extra": "10.0.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@midwayjs/core": "^3.0.0-beta.
|
|
35
|
-
"@midwayjs/express-session": "^3.0.0-beta.
|
|
34
|
+
"@midwayjs/core": "^3.0.0-beta.17",
|
|
35
|
+
"@midwayjs/express-session": "^3.0.0-beta.17",
|
|
36
36
|
"body-parser": "1.19.1",
|
|
37
37
|
"cookie-parser": "^1.4.6",
|
|
38
38
|
"express": "4.17.2"
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=12"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "17a8b5bd3d0b0b21f24dd2f165b5df9097fc3ec4"
|
|
49
49
|
}
|