@midwayjs/web 3.3.6 → 3.4.0-beta.2
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/web.d.ts +3 -10
- package/dist/framework/web.js +27 -6
- package/package.json +6 -6
package/dist/framework/web.d.ts
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import { BaseFramework, IMidwayBootstrapOptions
|
|
1
|
+
import { BaseFramework, IMidwayBootstrapOptions } from '@midwayjs/core';
|
|
2
2
|
import { MidwayFrameworkType } from '@midwayjs/decorator';
|
|
3
3
|
import { IMidwayWebConfigurationOptions, Application, Context } from '../interface';
|
|
4
|
-
import { EggRouter } from '@eggjs/router';
|
|
5
4
|
import { EggLogger } from 'egg';
|
|
6
|
-
declare class EggControllerGenerator extends WebControllerGenerator<EggRouter> {
|
|
7
|
-
readonly app: any;
|
|
8
|
-
constructor(app: any);
|
|
9
|
-
createRouter(routerOptions: any): EggRouter;
|
|
10
|
-
generateController(routeInfo: RouterInfo): (ctx: any, next: any) => Promise<void>;
|
|
11
|
-
}
|
|
12
5
|
export declare class MidwayWebFramework extends BaseFramework<Application, Context, IMidwayWebConfigurationOptions> {
|
|
13
6
|
protected loggers: {
|
|
14
7
|
[name: string]: EggLogger;
|
|
15
8
|
};
|
|
16
|
-
generator
|
|
9
|
+
private generator;
|
|
17
10
|
private server;
|
|
18
11
|
private agent;
|
|
19
12
|
private isClusterMode;
|
|
13
|
+
private webRouterService;
|
|
20
14
|
appDir: any;
|
|
21
15
|
configure(): any;
|
|
22
16
|
initSingleProcessEgg(): Promise<void>;
|
|
@@ -31,5 +25,4 @@ export declare class MidwayWebFramework extends BaseFramework<Application, Conte
|
|
|
31
25
|
beforeStop(): Promise<void>;
|
|
32
26
|
setServer(server: any): void;
|
|
33
27
|
}
|
|
34
|
-
export {};
|
|
35
28
|
//# sourceMappingURL=web.d.ts.map
|
package/dist/framework/web.js
CHANGED
|
@@ -18,9 +18,10 @@ const path_1 = require("path");
|
|
|
18
18
|
const util_1 = require("util");
|
|
19
19
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
20
20
|
class EggControllerGenerator extends core_1.WebControllerGenerator {
|
|
21
|
-
constructor(app) {
|
|
22
|
-
super(app);
|
|
21
|
+
constructor(app, webRouterService) {
|
|
22
|
+
super(app, webRouterService);
|
|
23
23
|
this.app = app;
|
|
24
|
+
this.webRouterService = webRouterService;
|
|
24
25
|
}
|
|
25
26
|
createRouter(routerOptions) {
|
|
26
27
|
const router = new router_1.EggRouter(routerOptions, this.app);
|
|
@@ -73,19 +74,39 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
73
74
|
this.app = options['application'];
|
|
74
75
|
}
|
|
75
76
|
// not found middleware
|
|
76
|
-
const
|
|
77
|
+
const midwayRouterNotFound = async (ctx, next) => {
|
|
77
78
|
await next();
|
|
78
79
|
if (!ctx._matchedRoute && ctx.body === undefined) {
|
|
79
80
|
throw new core_1.httpError.NotFoundError(`${ctx.path} Not Found`);
|
|
80
81
|
}
|
|
81
82
|
};
|
|
83
|
+
const bodyPatch = async (ctx, next) => {
|
|
84
|
+
await next();
|
|
85
|
+
if (ctx.body === undefined &&
|
|
86
|
+
!ctx.response._explicitStatus &&
|
|
87
|
+
ctx._matchedRoute) {
|
|
88
|
+
// 如果进了路由,重新赋值,防止 404
|
|
89
|
+
ctx.body = undefined;
|
|
90
|
+
}
|
|
91
|
+
if (ctx.response._midwayControllerNullBody &&
|
|
92
|
+
ctx.body &&
|
|
93
|
+
ctx.status === 204) {
|
|
94
|
+
ctx.status = 200;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
82
97
|
// insert error handler
|
|
83
98
|
const midwayRootMiddleware = async (ctx, next) => {
|
|
84
99
|
// this.app.createAnonymousContext(ctx);
|
|
85
|
-
|
|
100
|
+
this.middlewareManager.insertAfter(bodyPatch, 'notfound');
|
|
101
|
+
await (await this.applyMiddleware(midwayRouterNotFound))(ctx, next);
|
|
86
102
|
};
|
|
87
103
|
this.app.use(midwayRootMiddleware);
|
|
88
|
-
this.
|
|
104
|
+
this.webRouterService = await this.applicationContext.getAsync(core_1.MidwayWebRouterService, [
|
|
105
|
+
{
|
|
106
|
+
globalPrefix: this.configurationOptions.globalPrefix,
|
|
107
|
+
},
|
|
108
|
+
]);
|
|
109
|
+
this.generator = new EggControllerGenerator(this.app, this.webRouterService);
|
|
89
110
|
this.overwriteApplication('app');
|
|
90
111
|
this.app.loader.loadOrigin();
|
|
91
112
|
// 这里拦截 app.use 方法,让他可以加到 midway 的 middlewareManager 中
|
|
@@ -149,7 +170,7 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
149
170
|
async loadMidwayController() {
|
|
150
171
|
// move egg router to last
|
|
151
172
|
this.app.getMiddleware().findAndInsertLast('eggRouterMiddleware');
|
|
152
|
-
await this.generator.loadMidwayController(
|
|
173
|
+
await this.generator.loadMidwayController(newRouter => {
|
|
153
174
|
var _a;
|
|
154
175
|
const dispatchFn = newRouter.middleware();
|
|
155
176
|
dispatchFn._name = `midwayController(${((_a = newRouter === null || newRouter === void 0 ? void 0 : newRouter.opts) === null || _a === void 0 ? void 0 : _a.prefix) || '/'})`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/web",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-beta.2",
|
|
4
4
|
"description": "Midway Web Framework for Egg.js",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
],
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@midwayjs/decorator": "^3.
|
|
31
|
+
"@midwayjs/decorator": "^3.4.0-beta.2",
|
|
32
32
|
"@midwayjs/logger": "^2.15.0",
|
|
33
|
-
"@midwayjs/mock": "^3.
|
|
33
|
+
"@midwayjs/mock": "^3.4.0-beta.2",
|
|
34
34
|
"axios": "0.26.1",
|
|
35
35
|
"dayjs": "1.10.8",
|
|
36
36
|
"egg-logger": "2.7.1",
|
|
37
|
-
"egg-mock": "4.2.
|
|
37
|
+
"egg-mock": "4.2.1",
|
|
38
38
|
"egg-scripts": "2.15.3",
|
|
39
39
|
"egg-socket.io": "4.1.6",
|
|
40
40
|
"egg-view-nunjucks": "2.3.0",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@eggjs/router": "^2.0.0",
|
|
50
|
-
"@midwayjs/core": "^3.
|
|
50
|
+
"@midwayjs/core": "^3.4.0-beta.2",
|
|
51
51
|
"egg": "^2.28.0",
|
|
52
52
|
"egg-cluster": "^1.27.1",
|
|
53
53
|
"find-up": "5.0.0",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"engines": {
|
|
62
62
|
"node": ">=12"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "a61721d3946b30fd4cac183265edcd99b31ac72b"
|
|
65
65
|
}
|