@midwayjs/web 3.0.0-alpha.6 → 3.0.0-beta.11
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/CHANGELOG.md +123 -0
- package/README.md +1 -1
- package/agent.js +13 -6
- package/app/extend/agent.js +0 -4
- package/app/extend/application.js +0 -4
- package/app.js +16 -16
- package/config/config.default.js +13 -8
- package/config/plugin.js +6 -4
- package/dist/application.js +6 -6
- package/dist/base.js +94 -62
- package/dist/configuration.d.ts +13 -0
- package/dist/configuration.js +102 -0
- package/dist/framework/web.d.ts +25 -26
- package/dist/framework/web.js +191 -118
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/interface.d.ts +53 -12
- package/dist/logger.d.ts +35 -2
- package/dist/logger.js +84 -102
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +132 -9
- package/package.json +13 -14
- package/dist/framework/singleProcess.d.ts +0 -34
- package/dist/framework/singleProcess.js +0 -122
- package/dist/starter.d.ts +0 -12
- package/dist/starter.js +0 -23
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,129 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @midwayjs/web
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* default add session & bodyparser support for koa/express/faas ([#1420](https://github.com/midwayjs/midway/issues/1420)) ([cdaff31](https://github.com/midwayjs/midway/commit/cdaff317c3e862a95494a167995a28280af639bf))
|
|
20
|
+
* implement i18n for validate ([#1426](https://github.com/midwayjs/midway/issues/1426)) ([4c7ed2f](https://github.com/midwayjs/midway/commit/4c7ed2ff2e7ccf10f88f62abad230f92f5e76b97))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
|
|
27
|
+
|
|
28
|
+
**Note:** Version bump only for package @midwayjs/web
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Bug Fixes
|
|
38
|
+
|
|
39
|
+
* express routing middleware takes effect at the controller level ([#1364](https://github.com/midwayjs/midway/issues/1364)) ([b9272e0](https://github.com/midwayjs/midway/commit/b9272e0971003443304b0c53815be31a0061b4bd))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Bug Fixes
|
|
49
|
+
|
|
50
|
+
* middleware with ctx.body ([#1389](https://github.com/midwayjs/midway/issues/1389)) ([77af5c0](https://github.com/midwayjs/midway/commit/77af5c0b456f1843f4dcfd3dbfd2c0aa244c51bd))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
### Bug Fixes
|
|
60
|
+
|
|
61
|
+
* class transformer method missing ([#1387](https://github.com/midwayjs/midway/issues/1387)) ([074e839](https://github.com/midwayjs/midway/commit/074e8393598dc95e2742f735df75a2191c5fe25d))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
# [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
|
|
68
|
+
|
|
69
|
+
**Note:** Version bump only for package @midwayjs/web
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
### Bug Fixes
|
|
79
|
+
|
|
80
|
+
* logger close before bootstrap close ([#1370](https://github.com/midwayjs/midway/issues/1370)) ([6cc2720](https://github.com/midwayjs/midway/commit/6cc2720ed3445e8ffccc96d124b80ed7e2517f08))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
### Features
|
|
84
|
+
|
|
85
|
+
* add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
|
|
86
|
+
* auto transform args to type ([#1372](https://github.com/midwayjs/midway/issues/1372)) ([bb3f7d2](https://github.com/midwayjs/midway/commit/bb3f7d2028a034e1926d9df554849332354c3762))
|
|
87
|
+
* support global prefix url ([#1371](https://github.com/midwayjs/midway/issues/1371)) ([cc5fe44](https://github.com/midwayjs/midway/commit/cc5fe44e1d221590562dc71e1f33ae96093e0da7))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
### Features
|
|
97
|
+
|
|
98
|
+
* add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
|
|
105
|
+
|
|
106
|
+
**Note:** Version bump only for package @midwayjs/web
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
# [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
### Bug Fixes
|
|
116
|
+
|
|
117
|
+
* find egg plugin in cwd ([#1236](https://github.com/midwayjs/midway/issues/1236)) ([d9ac0ff](https://github.com/midwayjs/midway/commit/d9ac0ff6d4e7a58a8924636806d3894acf94fcd8))
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
### Features
|
|
121
|
+
|
|
122
|
+
* add http2 support ([#1242](https://github.com/midwayjs/midway/issues/1242)) ([6cda27e](https://github.com/midwayjs/midway/commit/6cda27e9e22689e46ace543326b43ae21b134911))
|
|
123
|
+
* add view, view-ejs and view-nunjucks ([#1308](https://github.com/midwayjs/midway/issues/1308)) ([a00f44b](https://github.com/midwayjs/midway/commit/a00f44bd769052245cd49d49ab417d621bb89caa))
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
6
129
|
## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
|
|
7
130
|
|
|
8
131
|
|
package/README.md
CHANGED
package/agent.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
const { debuglog } = require('util');
|
|
3
|
+
const debug = debuglog('midway:debug');
|
|
2
4
|
|
|
3
5
|
class AgentBootHook {
|
|
4
6
|
constructor(app) {
|
|
@@ -6,15 +8,20 @@ class AgentBootHook {
|
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
configDidLoad() {
|
|
9
|
-
|
|
10
|
-
// if use midway logger will be use midway custom context logger
|
|
11
|
-
this.app.ContextLogger = this.app.webFramework.BaseContextLoggerClass;
|
|
12
|
-
}
|
|
11
|
+
debug('[egg:lifecycle]: agent configDidLoad');
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
async didLoad() {
|
|
14
|
+
async didLoad() {
|
|
15
|
+
debug('[egg:lifecycle]: agent didLoad');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async willReady() {
|
|
19
|
+
debug('[egg:lifecycle]: agent willReady');
|
|
20
|
+
}
|
|
16
21
|
|
|
17
|
-
async
|
|
22
|
+
async beforeClose() {
|
|
23
|
+
debug('[egg:lifecycle]: agent beforeClose');
|
|
24
|
+
}
|
|
18
25
|
}
|
|
19
26
|
|
|
20
27
|
module.exports = AgentBootHook;
|
package/app/extend/agent.js
CHANGED
package/app.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const pathMatching = require('egg-path-matching');
|
|
4
|
+
const { debuglog } = require('util');
|
|
5
|
+
|
|
6
|
+
const debug = debuglog('midway:debug');
|
|
4
7
|
|
|
5
8
|
class AppBootHook {
|
|
6
9
|
constructor(app) {
|
|
@@ -10,35 +13,30 @@ class AppBootHook {
|
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
configDidLoad() {
|
|
16
|
+
debug('[egg lifecycle]: app configDidLoad');
|
|
13
17
|
// 先清空,防止加载到 midway 中间件出错
|
|
14
18
|
this.coreMiddleware = this.app.loader.config.coreMiddleware;
|
|
15
19
|
this.app.loader.config.coreMiddleware = [];
|
|
16
20
|
this.appMiddleware = this.app.loader.config.appMiddleware;
|
|
17
21
|
this.app.loader.config.appMiddleware = [];
|
|
18
|
-
if (this.app.config.midwayFeature['replaceEggLogger']) {
|
|
19
|
-
// if use midway logger will be use midway custom context logger
|
|
20
|
-
this.app.ContextLogger = this.app.webFramework.BaseContextLoggerClass;
|
|
21
|
-
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
async didLoad() {
|
|
25
|
+
debug('[egg lifecycle]: app didLoad');
|
|
25
26
|
if (this.app.loader['useEggSocketIO']) {
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
27
|
+
// egg socket.io 需要这个中间件
|
|
28
|
+
// const session = this.app.getMiddleware().findItem('session');
|
|
29
|
+
// this.app.middleware.push(session);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async willReady() {
|
|
34
|
-
|
|
34
|
+
debug('[egg lifecycle]: app willReady');
|
|
35
35
|
const middlewareNames = this.coreMiddleware.concat(this.appMiddleware);
|
|
36
36
|
// 等 midway 加载完成后,再去 use 中间件
|
|
37
37
|
for (const name of middlewareNames) {
|
|
38
38
|
if (this.app.getApplicationContext().registry.hasDefinition(name)) {
|
|
39
|
-
|
|
40
|
-
mwIns._name = name;
|
|
41
|
-
this.app.use(mwIns);
|
|
39
|
+
await this.app.useMiddleware(name);
|
|
42
40
|
} else {
|
|
43
41
|
// egg
|
|
44
42
|
const options = this.app.config[name] || {};
|
|
@@ -59,17 +57,19 @@ class AppBootHook {
|
|
|
59
57
|
return mw(ctx, next);
|
|
60
58
|
};
|
|
61
59
|
fn._name = mw._name + 'middlewareWrapper';
|
|
62
|
-
this.app.
|
|
60
|
+
await this.app.useMiddleware(fn);
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
64
|
|
|
67
|
-
this.app.
|
|
68
|
-
|
|
65
|
+
const eggRouterMiddleware = this.app.router.middleware();
|
|
66
|
+
eggRouterMiddleware._name = 'eggRouterMiddleware';
|
|
67
|
+
this.app.useMiddleware(eggRouterMiddleware);
|
|
68
|
+
this.app.emit('application-ready');
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
async beforeClose() {
|
|
72
|
-
|
|
72
|
+
debug('[egg lifecycle]: app beforeClose');
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
package/config/config.default.js
CHANGED
|
@@ -11,14 +11,19 @@ module.exports = appInfo => {
|
|
|
11
11
|
exports.rundir = path.join(appInfo.appDir, 'run');
|
|
12
12
|
|
|
13
13
|
// 修改默认的日志名
|
|
14
|
-
exports.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
exports.midwayLogger = {
|
|
15
|
+
clients: {
|
|
16
|
+
coreLogger: {
|
|
17
|
+
fileLogName: 'midway-core.log',
|
|
18
|
+
},
|
|
19
|
+
appLogger: {
|
|
20
|
+
fileLogName: 'midway-web.log',
|
|
21
|
+
aliasName: 'logger',
|
|
22
|
+
},
|
|
23
|
+
agentLogger: {
|
|
24
|
+
fileLogName: 'midway-agent.log',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
22
27
|
};
|
|
23
28
|
|
|
24
29
|
exports.pluginOverwrite = false;
|
package/config/plugin.js
CHANGED
|
@@ -4,8 +4,10 @@ module.exports = {
|
|
|
4
4
|
static: false,
|
|
5
5
|
development: false,
|
|
6
6
|
watcher: false,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
onerror: true,
|
|
8
|
+
multipart: true,
|
|
9
|
+
security: true,
|
|
10
|
+
logrotator: false,
|
|
11
|
+
view: false,
|
|
12
|
+
schedule: false,
|
|
11
13
|
};
|
package/dist/application.js
CHANGED
|
@@ -5,16 +5,16 @@ const path_1 = require("path");
|
|
|
5
5
|
const base_1 = require("./base");
|
|
6
6
|
const EGG_LOADER = Symbol.for('egg#loader');
|
|
7
7
|
const EGG_PATH = Symbol.for('egg#eggPath');
|
|
8
|
-
const EggAppWorkerLoader = base_1.createAppWorkerLoader();
|
|
9
|
-
const BaseEggApplication = base_1.createEggApplication();
|
|
10
|
-
const EggAgentWorkerLoader = base_1.createAgentWorkerLoader();
|
|
11
|
-
const BaseEggAgent = base_1.createEggAgent();
|
|
8
|
+
const EggAppWorkerLoader = (0, base_1.createAppWorkerLoader)();
|
|
9
|
+
const BaseEggApplication = (0, base_1.createEggApplication)();
|
|
10
|
+
const EggAgentWorkerLoader = (0, base_1.createAgentWorkerLoader)();
|
|
11
|
+
const BaseEggAgent = (0, base_1.createEggAgent)();
|
|
12
12
|
class EggApplication extends BaseEggApplication {
|
|
13
13
|
get [EGG_LOADER]() {
|
|
14
14
|
return EggAppWorkerLoader;
|
|
15
15
|
}
|
|
16
16
|
get [EGG_PATH]() {
|
|
17
|
-
return path_1.join(__dirname, '../');
|
|
17
|
+
return (0, path_1.join)(__dirname, '../');
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.Application = EggApplication;
|
|
@@ -23,7 +23,7 @@ class EggAgent extends BaseEggAgent {
|
|
|
23
23
|
return EggAgentWorkerLoader;
|
|
24
24
|
}
|
|
25
25
|
get [EGG_PATH]() {
|
|
26
|
-
return path_1.join(__dirname, '../');
|
|
26
|
+
return (0, path_1.join)(__dirname, '../');
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
exports.Agent = EggAgent;
|
package/dist/base.js
CHANGED
|
@@ -3,17 +3,17 @@ 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
5
|
const extend = require("extend2");
|
|
6
|
-
const web_1 = require("./framework/web");
|
|
7
6
|
const core_1 = require("@midwayjs/core");
|
|
8
7
|
const path_1 = require("path");
|
|
9
8
|
const fs_1 = require("fs");
|
|
10
9
|
const logger_1 = require("./logger");
|
|
11
10
|
const router_1 = require("@eggjs/router");
|
|
12
|
-
const
|
|
11
|
+
const util_1 = require("util");
|
|
13
12
|
const ROUTER = Symbol('EggCore#router');
|
|
14
13
|
const EGG_LOADER = Symbol.for('egg#loader');
|
|
15
14
|
const EGG_PATH = Symbol.for('egg#eggPath');
|
|
16
15
|
const LOGGERS = Symbol('EggApplication#loggers');
|
|
16
|
+
const debug = (0, util_1.debuglog)('midway:debug');
|
|
17
17
|
let customFramework = null;
|
|
18
18
|
function getFramework() {
|
|
19
19
|
if (customFramework)
|
|
@@ -21,8 +21,8 @@ function getFramework() {
|
|
|
21
21
|
/**
|
|
22
22
|
* create real egg loader and application object
|
|
23
23
|
*/
|
|
24
|
-
const pkg = core_1.safeRequire(path_1.join(process.env.MIDWAY_PROJECT_APPDIR || process.cwd(), 'package.json'), false);
|
|
25
|
-
customFramework = core_1.safelyGet('egg.framework', pkg);
|
|
24
|
+
const pkg = (0, core_1.safeRequire)((0, path_1.join)(process.env.MIDWAY_PROJECT_APPDIR || process.cwd(), 'package.json'), false);
|
|
25
|
+
customFramework = (0, core_1.safelyGet)('egg.framework', pkg);
|
|
26
26
|
if (customFramework) {
|
|
27
27
|
return customFramework;
|
|
28
28
|
}
|
|
@@ -39,24 +39,30 @@ const createAppWorkerLoader = () => {
|
|
|
39
39
|
this.useEggSocketIO = false;
|
|
40
40
|
}
|
|
41
41
|
getEggPaths() {
|
|
42
|
+
if ((0, core_1.getCurrentApplicationContext)()) {
|
|
43
|
+
this.singleProcessMode = true;
|
|
44
|
+
}
|
|
42
45
|
if (!this.appDir) {
|
|
43
46
|
// 这里的逻辑是为了兼容老 cluster 模式
|
|
44
47
|
if (this.app.options.typescript || this.app.options.isTsMode) {
|
|
45
48
|
process.env.EGG_TYPESCRIPT = 'true';
|
|
46
49
|
}
|
|
47
|
-
const result = utils_1.parseNormalDir(this.app.options['baseDir'], this.app.options.isTsMode);
|
|
50
|
+
const result = (0, utils_1.parseNormalDir)(this.app.options['baseDir'], this.app.options.isTsMode);
|
|
48
51
|
this.baseDir = result.baseDir;
|
|
49
52
|
this.options.baseDir = this.baseDir;
|
|
50
53
|
this.appDir = this.app.appDir = result.appDir;
|
|
51
54
|
}
|
|
52
55
|
const result = super.getEggPaths();
|
|
53
|
-
const monorepoRoot = utils_1.findLernaRoot();
|
|
56
|
+
const monorepoRoot = (0, utils_1.findLernaRoot)();
|
|
54
57
|
if (monorepoRoot) {
|
|
55
58
|
result.push(monorepoRoot);
|
|
56
59
|
}
|
|
57
60
|
if (process.env.MIDWAY_EGG_PLUGIN_PATH) {
|
|
58
61
|
result.push(process.env.MIDWAY_EGG_PLUGIN_PATH);
|
|
59
62
|
}
|
|
63
|
+
if (process.cwd() !== this.appDir) {
|
|
64
|
+
result.push(this.appDir);
|
|
65
|
+
}
|
|
60
66
|
const pathSet = new Set(result);
|
|
61
67
|
return Array.from(pathSet);
|
|
62
68
|
}
|
|
@@ -76,13 +82,13 @@ const createAppWorkerLoader = () => {
|
|
|
76
82
|
getServerEnv() {
|
|
77
83
|
// 这里和 egg 不同的是,一是修改了根路径,二是增加了环境变量
|
|
78
84
|
let serverEnv = this.options.env;
|
|
79
|
-
let envPath = path_1.join(this.appDir, 'config/env');
|
|
80
|
-
if (!serverEnv && fs_1.existsSync(envPath)) {
|
|
81
|
-
serverEnv = fs_1.readFileSync(envPath, 'utf8').trim();
|
|
85
|
+
let envPath = (0, path_1.join)(this.appDir, 'config/env');
|
|
86
|
+
if (!serverEnv && (0, fs_1.existsSync)(envPath)) {
|
|
87
|
+
serverEnv = (0, fs_1.readFileSync)(envPath, 'utf8').trim();
|
|
82
88
|
}
|
|
83
|
-
envPath = path_1.join(this.appDir, 'config/serverEnv');
|
|
84
|
-
if (!serverEnv && fs_1.existsSync(envPath)) {
|
|
85
|
-
serverEnv = fs_1.readFileSync(envPath, 'utf8').trim();
|
|
89
|
+
envPath = (0, path_1.join)(this.appDir, 'config/serverEnv');
|
|
90
|
+
if (!serverEnv && (0, fs_1.existsSync)(envPath)) {
|
|
91
|
+
serverEnv = (0, fs_1.readFileSync)(envPath, 'utf8').trim();
|
|
86
92
|
}
|
|
87
93
|
if (!serverEnv) {
|
|
88
94
|
serverEnv = process.env.MIDWAY_SERVER_ENV || process.env.EGG_SERVER_ENV;
|
|
@@ -99,35 +105,37 @@ const createAppWorkerLoader = () => {
|
|
|
99
105
|
return serverEnv;
|
|
100
106
|
}
|
|
101
107
|
load() {
|
|
102
|
-
this.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
.
|
|
113
|
-
|
|
114
|
-
})
|
|
115
|
-
.load(this.framework);
|
|
116
|
-
if (this.app.options['midwaySingleton'] !== true) {
|
|
117
|
-
// 这个代码只会在 egg-cluster 模式下执行
|
|
118
|
-
this.app.beforeStart(async () => {
|
|
119
|
-
await this.bootstrap.init();
|
|
120
|
-
super.load();
|
|
108
|
+
if (!this.singleProcessMode) {
|
|
109
|
+
// 多进程模式,从 egg-scripts 启动的
|
|
110
|
+
process.env['EGG_CLUSTER_MODE'] = 'true';
|
|
111
|
+
debug('[egg]: run with egg-scripts in cluster mode');
|
|
112
|
+
// 如果不走 bootstrap,就得在这里初始化 applicationContext
|
|
113
|
+
(0, core_1.initializeGlobalApplicationContext)({
|
|
114
|
+
...this.globalOptions,
|
|
115
|
+
appDir: this.appDir,
|
|
116
|
+
baseDir: this.baseDir,
|
|
117
|
+
ignore: ['**/app/extend/**'],
|
|
118
|
+
}).then(r => {
|
|
119
|
+
debug('[egg]: global context: init complete');
|
|
121
120
|
});
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
*/
|
|
127
|
-
async loadOrigin() {
|
|
128
|
-
await this.bootstrap.init();
|
|
123
|
+
loadOrigin() {
|
|
124
|
+
debug('[egg]: application: run load()');
|
|
129
125
|
super.load();
|
|
130
126
|
}
|
|
127
|
+
loadConfig() {
|
|
128
|
+
super.loadConfig();
|
|
129
|
+
if (this.singleProcessMode) {
|
|
130
|
+
const configService = (0, core_1.getCurrentApplicationContext)().get(core_1.MidwayConfigService);
|
|
131
|
+
configService.addObject(this.config);
|
|
132
|
+
Object.defineProperty(this, 'config', {
|
|
133
|
+
get() {
|
|
134
|
+
return configService.getConfiguration();
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
131
139
|
loadMiddleware() {
|
|
132
140
|
super.loadMiddleware();
|
|
133
141
|
if (this.plugins['io']) {
|
|
@@ -145,25 +153,31 @@ const createAgentWorkerLoader = () => {
|
|
|
145
153
|
var _a;
|
|
146
154
|
const AppWorkerLoader = ((_a = require(getFramework())) === null || _a === void 0 ? void 0 : _a.AgentWorkerLoader) ||
|
|
147
155
|
require('egg').AgentWorkerLoader;
|
|
148
|
-
class
|
|
156
|
+
class EggAgentWorkerLoader extends AppWorkerLoader {
|
|
149
157
|
getEggPaths() {
|
|
158
|
+
if ((0, core_1.getCurrentApplicationContext)()) {
|
|
159
|
+
this.singleProcessMode = true;
|
|
160
|
+
}
|
|
150
161
|
if (!this.appDir) {
|
|
151
162
|
if (this.app.options.typescript || this.app.options.isTsMode) {
|
|
152
163
|
process.env.EGG_TYPESCRIPT = 'true';
|
|
153
164
|
}
|
|
154
|
-
const result = utils_1.parseNormalDir(this.app.options['baseDir'], this.app.options.isTsMode);
|
|
165
|
+
const result = (0, utils_1.parseNormalDir)(this.app.options['baseDir'], this.app.options.isTsMode);
|
|
155
166
|
this.baseDir = result.baseDir;
|
|
156
167
|
this.options.baseDir = this.baseDir;
|
|
157
168
|
this.appDir = this.app.appDir = result.appDir;
|
|
158
169
|
}
|
|
159
170
|
const result = super.getEggPaths();
|
|
160
|
-
const monorepoRoot = utils_1.findLernaRoot();
|
|
171
|
+
const monorepoRoot = (0, utils_1.findLernaRoot)();
|
|
161
172
|
if (monorepoRoot) {
|
|
162
173
|
result.push(monorepoRoot);
|
|
163
174
|
}
|
|
164
175
|
if (process.env.MIDWAY_EGG_PLUGIN_PATH) {
|
|
165
176
|
result.push(process.env.MIDWAY_EGG_PLUGIN_PATH);
|
|
166
177
|
}
|
|
178
|
+
if (process.cwd() !== this.appDir) {
|
|
179
|
+
result.push(this.appDir);
|
|
180
|
+
}
|
|
167
181
|
const pathSet = new Set(result);
|
|
168
182
|
return Array.from(pathSet);
|
|
169
183
|
}
|
|
@@ -183,13 +197,13 @@ const createAgentWorkerLoader = () => {
|
|
|
183
197
|
getServerEnv() {
|
|
184
198
|
// 这里和 egg 不同的是,一是修改了根路径,二是增加了环境变量
|
|
185
199
|
let serverEnv = this.options.env;
|
|
186
|
-
let envPath = path_1.join(this.appDir, 'config/env');
|
|
187
|
-
if (!serverEnv && fs_1.existsSync(envPath)) {
|
|
188
|
-
serverEnv = fs_1.readFileSync(envPath, 'utf8').trim();
|
|
200
|
+
let envPath = (0, path_1.join)(this.appDir, 'config/env');
|
|
201
|
+
if (!serverEnv && (0, fs_1.existsSync)(envPath)) {
|
|
202
|
+
serverEnv = (0, fs_1.readFileSync)(envPath, 'utf8').trim();
|
|
189
203
|
}
|
|
190
|
-
envPath = path_1.join(this.appDir, 'config/serverEnv');
|
|
191
|
-
if (!serverEnv && fs_1.existsSync(envPath)) {
|
|
192
|
-
serverEnv = fs_1.readFileSync(envPath, 'utf8').trim();
|
|
204
|
+
envPath = (0, path_1.join)(this.appDir, 'config/serverEnv');
|
|
205
|
+
if (!serverEnv && (0, fs_1.existsSync)(envPath)) {
|
|
206
|
+
serverEnv = (0, fs_1.readFileSync)(envPath, 'utf8').trim();
|
|
193
207
|
}
|
|
194
208
|
if (!serverEnv) {
|
|
195
209
|
serverEnv = process.env.MIDWAY_SERVER_ENV || process.env.EGG_SERVER_ENV;
|
|
@@ -206,26 +220,32 @@ const createAgentWorkerLoader = () => {
|
|
|
206
220
|
return serverEnv;
|
|
207
221
|
}
|
|
208
222
|
load() {
|
|
209
|
-
this.framework = new web_1.MidwayWebFramework().configure({
|
|
210
|
-
processType: 'agent',
|
|
211
|
-
app: this.app,
|
|
212
|
-
globalConfig: this.app.config,
|
|
213
|
-
});
|
|
214
|
-
this.bootstrap = new starter_1.WebBootstrapStarter({
|
|
215
|
-
isWorker: false,
|
|
216
|
-
});
|
|
217
|
-
this.bootstrap
|
|
218
|
-
.configure({
|
|
219
|
-
appDir: this.app.appDir,
|
|
220
|
-
})
|
|
221
|
-
.load(this.framework);
|
|
222
223
|
this.app.beforeStart(async () => {
|
|
223
|
-
|
|
224
|
+
debug('[egg]: start "initializeAgentApplicationContext"');
|
|
225
|
+
await (0, utils_1.initializeAgentApplicationContext)(this.app, {
|
|
226
|
+
...this.globalOptions,
|
|
227
|
+
appDir: this.appDir,
|
|
228
|
+
baseDir: this.baseDir,
|
|
229
|
+
ignore: ['**/app/extend/**'],
|
|
230
|
+
});
|
|
224
231
|
super.load();
|
|
232
|
+
debug('[egg]: agent load run complete');
|
|
225
233
|
});
|
|
226
234
|
}
|
|
235
|
+
loadConfig() {
|
|
236
|
+
super.loadConfig();
|
|
237
|
+
if (this.singleProcessMode) {
|
|
238
|
+
const configService = (0, core_1.getCurrentApplicationContext)().get(core_1.MidwayConfigService);
|
|
239
|
+
configService.addObject(this.config);
|
|
240
|
+
Object.defineProperty(this, 'config', {
|
|
241
|
+
get() {
|
|
242
|
+
return configService.getConfiguration();
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
227
247
|
}
|
|
228
|
-
return
|
|
248
|
+
return EggAgentWorkerLoader;
|
|
229
249
|
};
|
|
230
250
|
exports.createAgentWorkerLoader = createAgentWorkerLoader;
|
|
231
251
|
const createEggApplication = () => {
|
|
@@ -244,7 +264,7 @@ const createEggApplication = () => {
|
|
|
244
264
|
}
|
|
245
265
|
get loggers() {
|
|
246
266
|
if (!this[LOGGERS]) {
|
|
247
|
-
this[LOGGERS] = logger_1.createLoggers(this);
|
|
267
|
+
this[LOGGERS] = (0, logger_1.createLoggers)(this, 'app');
|
|
248
268
|
}
|
|
249
269
|
return this[LOGGERS];
|
|
250
270
|
}
|
|
@@ -255,6 +275,12 @@ const createEggApplication = () => {
|
|
|
255
275
|
const router = (this[ROUTER] = new router_1.EggRouter({ sensitive: true }, this));
|
|
256
276
|
return router;
|
|
257
277
|
}
|
|
278
|
+
dumpConfig() {
|
|
279
|
+
var _a, _b;
|
|
280
|
+
if (((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.egg) === null || _b === void 0 ? void 0 : _b.dumpConfig) !== false) {
|
|
281
|
+
super.dumpConfig();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
258
284
|
}
|
|
259
285
|
return EggApplication;
|
|
260
286
|
};
|
|
@@ -275,10 +301,16 @@ const createEggAgent = () => {
|
|
|
275
301
|
}
|
|
276
302
|
get loggers() {
|
|
277
303
|
if (!this[LOGGERS]) {
|
|
278
|
-
this[LOGGERS] = logger_1.createLoggers(this);
|
|
304
|
+
this[LOGGERS] = (0, logger_1.createLoggers)(this, 'agent');
|
|
279
305
|
}
|
|
280
306
|
return this[LOGGERS];
|
|
281
307
|
}
|
|
308
|
+
dumpConfig() {
|
|
309
|
+
var _a, _b;
|
|
310
|
+
if (((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.egg) === null || _b === void 0 ? void 0 : _b.dumpConfig) !== false) {
|
|
311
|
+
super.dumpConfig();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
282
314
|
}
|
|
283
315
|
return EggAgent;
|
|
284
316
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IMidwayWebApplication } from './interface';
|
|
2
|
+
import { MidwayDecoratorService } from '@midwayjs/core';
|
|
3
|
+
export declare class EggConfiguration {
|
|
4
|
+
baseDir: any;
|
|
5
|
+
appDir: any;
|
|
6
|
+
app: IMidwayWebApplication;
|
|
7
|
+
decoratorService: MidwayDecoratorService;
|
|
8
|
+
init(): void;
|
|
9
|
+
onReady(): Promise<void>;
|
|
10
|
+
onServerReady(): Promise<void>;
|
|
11
|
+
onStop(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=configuration.d.ts.map
|