@midwayjs/web 3.4.0-beta.1 → 3.4.0-beta.10
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/LICENSE +21 -0
- package/dist/framework/web.d.ts +3 -10
- package/dist/framework/web.js +27 -6
- package/dist/logger.js +2 -1
- package/package.json +9 -9
- package/CHANGELOG.md +0 -1557
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.
|
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/dist/logger.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/web",
|
|
3
|
-
"version": "3.4.0-beta.
|
|
3
|
+
"version": "3.4.0-beta.10",
|
|
4
4
|
"description": "Midway Web Framework for Egg.js",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
],
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@midwayjs/decorator": "^3.4.0-beta.
|
|
31
|
+
"@midwayjs/decorator": "^3.4.0-beta.10",
|
|
32
32
|
"@midwayjs/logger": "^2.15.0",
|
|
33
|
-
"@midwayjs/mock": "^3.4.0-beta.
|
|
34
|
-
"axios": "0.
|
|
35
|
-
"dayjs": "1.
|
|
36
|
-
"egg-logger": "2.
|
|
33
|
+
"@midwayjs/mock": "^3.4.0-beta.10",
|
|
34
|
+
"axios": "0.27.2",
|
|
35
|
+
"dayjs": "1.11.3",
|
|
36
|
+
"egg-logger": "2.8.0",
|
|
37
37
|
"egg-mock": "4.2.1",
|
|
38
|
-
"egg-scripts": "2.
|
|
38
|
+
"egg-scripts": "2.17.0",
|
|
39
39
|
"egg-socket.io": "4.1.6",
|
|
40
40
|
"egg-view-nunjucks": "2.3.0",
|
|
41
41
|
"fake-egg": "1.0.0",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@eggjs/router": "^2.0.0",
|
|
50
|
-
"@midwayjs/core": "^3.4.0-beta.
|
|
50
|
+
"@midwayjs/core": "^3.4.0-beta.10",
|
|
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": "560a5fa311605e4008c55f31c31bc4e12eeff2a5"
|
|
65
65
|
}
|