@midwayjs/web 3.0.0-beta.6 → 3.0.0
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/app.js +3 -4
- package/config/plugin.js +4 -3
- package/dist/base.js +2 -3
- package/dist/configuration.d.ts +1 -1
- package/dist/configuration.js +5 -1
- package/dist/framework/web.d.ts +2 -4
- package/dist/framework/web.js +41 -26
- package/dist/interface.d.ts +1 -1
- package/dist/logger.js +1 -2
- package/dist/utils.js +3 -3
- package/package.json +19 -20
- package/CHANGELOG.md +0 -1158
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @midwayjs/web
|
|
2
2
|
|
|
3
|
-
[](http://packagequality.com/#?package=@midwayjs/web)
|
|
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
|
|
package/app.js
CHANGED
|
@@ -24,10 +24,9 @@ class AppBootHook {
|
|
|
24
24
|
async didLoad() {
|
|
25
25
|
debug('[egg lifecycle]: app didLoad');
|
|
26
26
|
if (this.app.loader['useEggSocketIO']) {
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
27
|
+
// egg socket.io 需要这个中间件
|
|
28
|
+
// const session = this.app.getMiddleware().findItem('session');
|
|
29
|
+
// this.app.middleware.push(session);
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
|
package/config/plugin.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = {
|
|
4
|
+
onerror: true,
|
|
5
|
+
security: true,
|
|
4
6
|
static: false,
|
|
5
7
|
development: false,
|
|
6
8
|
watcher: false,
|
|
7
|
-
|
|
8
|
-
multipart: true,
|
|
9
|
-
security: true,
|
|
9
|
+
multipart: false,
|
|
10
10
|
logrotator: false,
|
|
11
11
|
view: false,
|
|
12
12
|
schedule: false,
|
|
13
|
+
i18n: false,
|
|
13
14
|
};
|
package/dist/base.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createEggAgent = exports.createEggApplication = exports.createAgentWorkerLoader = exports.createAppWorkerLoader = void 0;
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
|
-
const extend = require("extend2");
|
|
6
5
|
const core_1 = require("@midwayjs/core");
|
|
7
6
|
const path_1 = require("path");
|
|
8
7
|
const fs_1 = require("fs");
|
|
@@ -70,7 +69,7 @@ const createAppWorkerLoader = () => {
|
|
|
70
69
|
if (!this.appInfo) {
|
|
71
70
|
const appInfo = super.getAppInfo();
|
|
72
71
|
// ROOT == HOME in prod env
|
|
73
|
-
this.appInfo = extend(true, appInfo, {
|
|
72
|
+
this.appInfo = (0, core_1.extend)(true, appInfo, {
|
|
74
73
|
root: appInfo.env === 'local' || appInfo.env === 'unittest'
|
|
75
74
|
? this.appDir
|
|
76
75
|
: appInfo.root,
|
|
@@ -185,7 +184,7 @@ const createAgentWorkerLoader = () => {
|
|
|
185
184
|
if (!this.appInfo) {
|
|
186
185
|
const appInfo = super.getAppInfo();
|
|
187
186
|
// ROOT == HOME in prod env
|
|
188
|
-
this.appInfo = extend(true, appInfo, {
|
|
187
|
+
this.appInfo = (0, core_1.extend)(true, appInfo, {
|
|
189
188
|
root: appInfo.env === 'local' || appInfo.env === 'unittest'
|
|
190
189
|
? this.appDir
|
|
191
190
|
: appInfo.root,
|
package/dist/configuration.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare class EggConfiguration {
|
|
|
6
6
|
app: IMidwayWebApplication;
|
|
7
7
|
decoratorService: MidwayDecoratorService;
|
|
8
8
|
init(): void;
|
|
9
|
-
onReady(
|
|
9
|
+
onReady(): Promise<void>;
|
|
10
10
|
onServerReady(): Promise<void>;
|
|
11
11
|
onStop(): Promise<void>;
|
|
12
12
|
}
|
package/dist/configuration.js
CHANGED
|
@@ -18,7 +18,11 @@ let EggConfiguration = class EggConfiguration {
|
|
|
18
18
|
return (0, core_1.extractKoaLikeValue)(options.metadata.type, options.metadata.propertyData, options.originParamType)(options.originArgs[0], options.originArgs[1]);
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
async onReady(
|
|
21
|
+
async onReady() {
|
|
22
|
+
// ps: 本想在这里清理掉egg添加的中间件,但是这里的数组已经只有一个 midway root middleware,其他的 getter 都是 egg 加进去的,但是不会被中间件执行,所以不需要清理
|
|
23
|
+
// 去掉为了 egg-socket.io 报错扫进去的 session
|
|
24
|
+
this.app.middleware = this.app.middleware.slice(0);
|
|
25
|
+
}
|
|
22
26
|
async onServerReady() {
|
|
23
27
|
// trigger server didReady
|
|
24
28
|
this.app.messenger.emit('egg-ready');
|
package/dist/framework/web.d.ts
CHANGED
|
@@ -5,9 +5,7 @@ import { EggRouter } from '@eggjs/router';
|
|
|
5
5
|
import { Application, Context, EggLogger } from 'egg';
|
|
6
6
|
declare class EggControllerGenerator extends WebControllerGenerator<EggRouter> {
|
|
7
7
|
readonly app: any;
|
|
8
|
-
|
|
9
|
-
readonly logger: any;
|
|
10
|
-
constructor(app: any, applicationContext: any, logger: any);
|
|
8
|
+
constructor(app: any);
|
|
11
9
|
createRouter(routerOptions: any): EggRouter;
|
|
12
10
|
generateController(routeInfo: RouterInfo): (ctx: any, next: any) => Promise<void>;
|
|
13
11
|
}
|
|
@@ -29,7 +27,7 @@ export declare class MidwayWebFramework extends BaseFramework<Application, Conte
|
|
|
29
27
|
run(): Promise<void>;
|
|
30
28
|
getLogger(name?: string): any;
|
|
31
29
|
setContextLoggerClass(BaseContextLogger: any): void;
|
|
32
|
-
generateMiddleware(middlewareId:
|
|
30
|
+
generateMiddleware(middlewareId: any): Promise<any>;
|
|
33
31
|
beforeStop(): Promise<void>;
|
|
34
32
|
}
|
|
35
33
|
export {};
|
package/dist/framework/web.js
CHANGED
|
@@ -19,11 +19,9 @@ const util_1 = require("util");
|
|
|
19
19
|
const logger_2 = require("../logger");
|
|
20
20
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
21
21
|
class EggControllerGenerator extends core_1.WebControllerGenerator {
|
|
22
|
-
constructor(app
|
|
23
|
-
super(
|
|
22
|
+
constructor(app) {
|
|
23
|
+
super(app);
|
|
24
24
|
this.app = app;
|
|
25
|
-
this.applicationContext = applicationContext;
|
|
26
|
-
this.logger = logger;
|
|
27
25
|
}
|
|
28
26
|
createRouter(routerOptions) {
|
|
29
27
|
const router = new router_1.EggRouter(routerOptions, this.app);
|
|
@@ -71,18 +69,20 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
71
69
|
if (!this.isClusterMode) {
|
|
72
70
|
await this.initSingleProcessEgg();
|
|
73
71
|
}
|
|
72
|
+
// not found middleware
|
|
73
|
+
const notFound = async (ctx, next) => {
|
|
74
|
+
await next();
|
|
75
|
+
if (!ctx._matchedRoute) {
|
|
76
|
+
throw new core_1.httpError.NotFoundError();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
74
79
|
// insert error handler
|
|
75
|
-
|
|
80
|
+
const midwayRootMiddleware = async (ctx, next) => {
|
|
76
81
|
// this.app.createAnonymousContext(ctx);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (result) {
|
|
82
|
-
ctx.body = result;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
this.generator = new EggControllerGenerator(this.app, this.applicationContext, this.appLogger);
|
|
82
|
+
await (await this.applyMiddleware(notFound))(ctx, next);
|
|
83
|
+
};
|
|
84
|
+
this.app.use(midwayRootMiddleware);
|
|
85
|
+
this.generator = new EggControllerGenerator(this.app);
|
|
86
86
|
this.overwriteApplication('app');
|
|
87
87
|
await new Promise(resolve => {
|
|
88
88
|
this.app.once('application-ready', () => {
|
|
@@ -90,7 +90,7 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
90
90
|
resolve();
|
|
91
91
|
});
|
|
92
92
|
this.app.loader.loadOrigin();
|
|
93
|
-
//
|
|
93
|
+
// 这里拦截 app.use 方法,让他可以加到 midway 的 middlewareManager 中
|
|
94
94
|
this.app.originUse = this.app.use;
|
|
95
95
|
this.app.use = this.app.useMiddleware;
|
|
96
96
|
this.app.ready();
|
|
@@ -115,6 +115,13 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
115
115
|
});
|
|
116
116
|
debug(`[egg]: overwrite properties to "${processType}"`);
|
|
117
117
|
this.defineApplicationProperties({
|
|
118
|
+
generateController: (controllerMapping) => {
|
|
119
|
+
const [controllerId, methodName] = controllerMapping.split('.');
|
|
120
|
+
return this.generator.generateController({
|
|
121
|
+
id: controllerId,
|
|
122
|
+
method: methodName,
|
|
123
|
+
});
|
|
124
|
+
},
|
|
118
125
|
generateMiddleware: async (middlewareId) => {
|
|
119
126
|
return this.generateMiddleware(middlewareId);
|
|
120
127
|
},
|
|
@@ -134,7 +141,10 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
134
141
|
}
|
|
135
142
|
async loadMidwayController() {
|
|
136
143
|
await this.generator.loadMidwayController(this.configurationOptions.globalPrefix, newRouter => {
|
|
137
|
-
|
|
144
|
+
var _a;
|
|
145
|
+
const dispatchFn = newRouter.middleware();
|
|
146
|
+
dispatchFn._name = `midwayController(${((_a = newRouter === null || newRouter === void 0 ? void 0 : newRouter.opts) === null || _a === void 0 ? void 0 : _a.prefix) || '/'})`;
|
|
147
|
+
this.app.useMiddleware(dispatchFn);
|
|
138
148
|
});
|
|
139
149
|
}
|
|
140
150
|
getFrameworkType() {
|
|
@@ -142,10 +152,13 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
142
152
|
}
|
|
143
153
|
async run() {
|
|
144
154
|
var _a;
|
|
155
|
+
// move egg router to last
|
|
156
|
+
this.app.getMiddleware().findAndInsertLast('eggRouterMiddleware');
|
|
145
157
|
// load controller
|
|
146
158
|
await this.loadMidwayController();
|
|
147
159
|
// restore use method
|
|
148
160
|
this.app.use = this.app.originUse;
|
|
161
|
+
debug(`[egg]: current middleware = ${this.middlewareManager.getNames()}`);
|
|
149
162
|
if (!this.isClusterMode) {
|
|
150
163
|
// https config
|
|
151
164
|
if (this.configurationOptions.key && this.configurationOptions.cert) {
|
|
@@ -176,17 +189,19 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
176
189
|
const eggConfig = this.configService.getConfiguration('egg');
|
|
177
190
|
if (!this.isClusterMode && eggConfig) {
|
|
178
191
|
const customPort = (_a = process.env.MIDWAY_HTTP_PORT) !== null && _a !== void 0 ? _a : eggConfig.port;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
192
|
+
if (customPort) {
|
|
193
|
+
new Promise(resolve => {
|
|
194
|
+
const args = [customPort];
|
|
195
|
+
if (eggConfig.hostname) {
|
|
196
|
+
args.push(eggConfig.hostname);
|
|
197
|
+
}
|
|
198
|
+
args.push(() => {
|
|
199
|
+
resolve();
|
|
200
|
+
});
|
|
201
|
+
this.server.listen(...args);
|
|
202
|
+
process.env.MIDWAY_HTTP_PORT = String(customPort);
|
|
186
203
|
});
|
|
187
|
-
|
|
188
|
-
process.env.MIDWAY_HTTP_PORT = String(customPort);
|
|
189
|
-
});
|
|
204
|
+
}
|
|
190
205
|
}
|
|
191
206
|
}
|
|
192
207
|
}
|
package/dist/interface.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface IMidwayWebBaseApplication {
|
|
|
7
7
|
applicationContext: IMidwayContainer;
|
|
8
8
|
getLogger(name?: string): ILogger;
|
|
9
9
|
getCoreLogger(): ILogger;
|
|
10
|
-
generateMiddleware?(middlewareId:
|
|
10
|
+
generateMiddleware?(middlewareId: any): Promise<Middleware<DefaultState, EggContext>>;
|
|
11
11
|
createLogger(name: string, options: LoggerOptions): ILogger;
|
|
12
12
|
}
|
|
13
13
|
declare module 'egg' {
|
package/dist/logger.js
CHANGED
|
@@ -7,7 +7,6 @@ const fs_1 = require("fs");
|
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
8
|
const os = require("os");
|
|
9
9
|
const core_1 = require("@midwayjs/core");
|
|
10
|
-
const extend = require("extend2");
|
|
11
10
|
const util_1 = require("util");
|
|
12
11
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
13
12
|
const isWindows = os.platform() === 'win32';
|
|
@@ -97,7 +96,7 @@ class MidwayLoggers extends Map {
|
|
|
97
96
|
},
|
|
98
97
|
};
|
|
99
98
|
const midwayLoggerConfig = loggerService.transformEggLogger(options);
|
|
100
|
-
extend(true, options, midwayLoggerConfig);
|
|
99
|
+
(0, core_1.extend)(true, options, midwayLoggerConfig);
|
|
101
100
|
if ((_a = options === null || options === void 0 ? void 0 : options.midwayLogger) === null || _a === void 0 ? void 0 : _a.clients) {
|
|
102
101
|
// 从 egg 过来,这里有可能没有 dir
|
|
103
102
|
if (!((_b = options.midwayLogger['default']) === null || _b === void 0 ? void 0 : _b.dir)) {
|
package/dist/utils.js
CHANGED
|
@@ -117,12 +117,12 @@ async function initializeAgentApplicationContext(agent, globalOptions) {
|
|
|
117
117
|
const aspectService = await applicationContext.getAsync(core_1.MidwayAspectService, [applicationContext]);
|
|
118
118
|
// init decorator service
|
|
119
119
|
const decoratorService = await applicationContext.getAsync(core_1.MidwayDecoratorService, [applicationContext]);
|
|
120
|
-
if (!globalOptions.
|
|
121
|
-
globalOptions.
|
|
120
|
+
if (!globalOptions.imports) {
|
|
121
|
+
globalOptions.imports = [
|
|
122
122
|
(0, core_1.safeRequire)((0, path_1.join)(globalOptions.baseDir, 'configuration')),
|
|
123
123
|
];
|
|
124
124
|
}
|
|
125
|
-
for (const configurationModule of [].concat(globalOptions.
|
|
125
|
+
for (const configurationModule of [].concat(globalOptions.imports)) {
|
|
126
126
|
// load configuration and component
|
|
127
127
|
applicationContext.load(configurationModule);
|
|
128
128
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/web",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Midway Web Framework for Egg.js",
|
|
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
|
"link": "npm link"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
@@ -27,27 +27,26 @@
|
|
|
27
27
|
],
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@midwayjs/decorator": "^3.0.0
|
|
31
|
-
"@midwayjs/
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"egg-
|
|
35
|
-
"egg-
|
|
36
|
-
"egg-
|
|
30
|
+
"@midwayjs/decorator": "^3.0.0",
|
|
31
|
+
"@midwayjs/logger": "2.14.0",
|
|
32
|
+
"@midwayjs/mock": "^3.0.0",
|
|
33
|
+
"dayjs": "1.10.7",
|
|
34
|
+
"egg-logger": "2.7.1",
|
|
35
|
+
"egg-mock": "4.2.0",
|
|
36
|
+
"egg-socket.io": "4.1.6",
|
|
37
|
+
"egg-view-nunjucks": "2.3.0",
|
|
37
38
|
"fake-egg": "1.0.0",
|
|
38
|
-
"fs-extra": "
|
|
39
|
-
"mm": "3",
|
|
40
|
-
"pedding": "
|
|
41
|
-
"react": "
|
|
42
|
-
"react-dom": "
|
|
39
|
+
"fs-extra": "10.0.0",
|
|
40
|
+
"mm": "3.2.0",
|
|
41
|
+
"pedding": "1.1.0",
|
|
42
|
+
"react": "17.0.2",
|
|
43
|
+
"react-dom": "17.0.2"
|
|
43
44
|
},
|
|
44
45
|
"dependencies": {
|
|
45
46
|
"@eggjs/router": "^2.0.0",
|
|
46
|
-
"@midwayjs/core": "^3.0.0
|
|
47
|
-
"@midwayjs/logger": "^3.0.0-beta.6",
|
|
47
|
+
"@midwayjs/core": "^3.0.0",
|
|
48
48
|
"egg": "^2.28.0",
|
|
49
|
-
"
|
|
50
|
-
"find-up": "^5.0.0",
|
|
49
|
+
"find-up": "5.0.0",
|
|
51
50
|
"mkdirp": "^1.0.4"
|
|
52
51
|
},
|
|
53
52
|
"author": "Harry Chen <czy88840616@gmail.com>",
|
|
@@ -58,5 +57,5 @@
|
|
|
58
57
|
"engines": {
|
|
59
58
|
"node": ">=12"
|
|
60
59
|
},
|
|
61
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "55c26029bccf7bbb739fa1597e8f418dafa2caa0"
|
|
62
61
|
}
|