@midwayjs/web 3.0.0-alpha.9 → 3.0.0-beta.4

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 CHANGED
@@ -3,6 +3,60 @@
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.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * logger close before bootstrap close ([#1370](https://github.com/midwayjs/midway/issues/1370)) ([6cc2720](https://github.com/midwayjs/midway/commit/6cc2720ed3445e8ffccc96d124b80ed7e2517f08))
12
+
13
+
14
+ ### Features
15
+
16
+ * add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
17
+ * auto transform args to type ([#1372](https://github.com/midwayjs/midway/issues/1372)) ([bb3f7d2](https://github.com/midwayjs/midway/commit/bb3f7d2028a034e1926d9df554849332354c3762))
18
+ * support global prefix url ([#1371](https://github.com/midwayjs/midway/issues/1371)) ([cc5fe44](https://github.com/midwayjs/midway/commit/cc5fe44e1d221590562dc71e1f33ae96093e0da7))
19
+
20
+
21
+
22
+
23
+
24
+ # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
25
+
26
+
27
+ ### Features
28
+
29
+ * add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
30
+
31
+
32
+
33
+
34
+
35
+ # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
36
+
37
+ **Note:** Version bump only for package @midwayjs/web
38
+
39
+
40
+
41
+
42
+
43
+ # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
44
+
45
+
46
+ ### Bug Fixes
47
+
48
+ * find egg plugin in cwd ([#1236](https://github.com/midwayjs/midway/issues/1236)) ([d9ac0ff](https://github.com/midwayjs/midway/commit/d9ac0ff6d4e7a58a8924636806d3894acf94fcd8))
49
+
50
+
51
+ ### Features
52
+
53
+ * add http2 support ([#1242](https://github.com/midwayjs/midway/issues/1242)) ([6cda27e](https://github.com/midwayjs/midway/commit/6cda27e9e22689e46ace543326b43ae21b134911))
54
+ * add view, view-ejs and view-nunjucks ([#1308](https://github.com/midwayjs/midway/issues/1308)) ([a00f44b](https://github.com/midwayjs/midway/commit/a00f44bd769052245cd49d49ab417d621bb89caa))
55
+
56
+
57
+
58
+
59
+
6
60
  ## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
7
61
 
8
62
 
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
- if (this.app.config.midwayFeature['replaceEggLogger']) {
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 willReady() {}
22
+ async beforeClose() {
23
+ debug('[egg:lifecycle]: agent beforeClose');
24
+ }
18
25
  }
19
26
 
20
27
  module.exports = AgentBootHook;
@@ -6,8 +6,4 @@ module.exports = {
6
6
  get appDir() {
7
7
  return this.loader.appDir;
8
8
  },
9
-
10
- get webFramework() {
11
- return this.loader.framework;
12
- },
13
9
  };
@@ -2,8 +2,4 @@ module.exports = {
2
2
  get baseDir() {
3
3
  return this.loader.baseDir;
4
4
  },
5
-
6
- get webFramework() {
7
- return this.loader.framework;
8
- },
9
5
  };
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,18 +13,16 @@ 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
  // socketio 下会提前加入 session 中间件,这里删除,防止重复加载
27
28
  if (this.app.middleware.length && this.app.middleware[this.app.middleware.length - 1]._name === 'session') {
@@ -31,14 +32,12 @@ class AppBootHook {
31
32
  }
32
33
 
33
34
  async willReady() {
34
- await this.app.webFramework.loadExtension();
35
+ debug('[egg lifecycle]: app willReady');
35
36
  const middlewareNames = this.coreMiddleware.concat(this.appMiddleware);
36
37
  // 等 midway 加载完成后,再去 use 中间件
37
38
  for (const name of middlewareNames) {
38
39
  if (this.app.getApplicationContext().registry.hasDefinition(name)) {
39
- const mwIns = await this.app.generateMiddleware(name);
40
- mwIns._name = name;
41
- this.app.use(mwIns);
40
+ await this.app.useMiddleware(name);
42
41
  } else {
43
42
  // egg
44
43
  const options = this.app.config[name] || {};
@@ -59,17 +58,19 @@ class AppBootHook {
59
58
  return mw(ctx, next);
60
59
  };
61
60
  fn._name = mw._name + 'middlewareWrapper';
62
- this.app.use(fn);
61
+ await this.app.useMiddleware(fn);
63
62
  }
64
63
  }
65
64
  }
66
65
 
67
- this.app.use(this.app.router.middleware());
68
- await this.app.webFramework.loadMidwayController();
66
+ const eggRouterMiddleware = this.app.router.middleware();
67
+ eggRouterMiddleware._name = 'eggRouterMiddleware';
68
+ this.app.useMiddleware(eggRouterMiddleware);
69
+ this.app.emit('application-ready');
69
70
  }
70
71
 
71
72
  async beforeClose() {
72
- await this.app.webFramework.stop();
73
+ debug('[egg lifecycle]: app beforeClose');
73
74
  }
74
75
  }
75
76
 
@@ -11,14 +11,19 @@ module.exports = appInfo => {
11
11
  exports.rundir = path.join(appInfo.appDir, 'run');
12
12
 
13
13
  // 修改默认的日志名
14
- exports.logger = {
15
- appLogName: 'midway-web.log',
16
- coreLogName: 'midway-core.log',
17
- agentLogName: 'midway-agent.log',
18
- };
19
-
20
- exports.midwayFeature = {
21
- replaceEggLogger: false,
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
- schedulePlus: {
8
- enable: true,
9
- package: 'midway-schedule',
10
- },
7
+ onerror: true,
8
+ multipart: true,
9
+ security: true,
10
+ logrotator: false,
11
+ view: false,
12
+ schedule: false,
11
13
  };
@@ -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 starter_1 = require("./starter");
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.framework = new web_1.MidwayWebFramework().configure({
103
- processType: 'application',
104
- app: this.app,
105
- globalConfig: this.app.config,
106
- });
107
- this.bootstrap = new starter_1.WebBootstrapStarter({
108
- isWorker: true,
109
- applicationContext: this.app.options.applicationContext,
110
- });
111
- this.bootstrap
112
- .configure({
113
- appDir: this.app.appDir,
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
- * 这个代码只会在单进程 bootstrap.js 模式下执行
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 EggAppWorkerLoader extends AppWorkerLoader {
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
- await this.bootstrap.init();
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 EggAppWorkerLoader;
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(container: any): Promise<void>;
10
+ onServerReady(): Promise<void>;
11
+ onStop(): Promise<void>;
12
+ }
13
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.EggConfiguration = void 0;
13
+ const decorator_1 = require("@midwayjs/decorator");
14
+ const core_1 = require("@midwayjs/core");
15
+ let EggConfiguration = class EggConfiguration {
16
+ init() {
17
+ this.decoratorService.registerParameterHandler(decorator_1.WEB_ROUTER_PARAM_KEY, options => {
18
+ return (0, core_1.extractKoaLikeValue)(options.metadata.type, options.metadata.propertyData, options.originParamType)(options.originArgs[0], options.originArgs[1]);
19
+ });
20
+ }
21
+ async onReady(container) { }
22
+ async onServerReady() {
23
+ // trigger server didReady
24
+ this.app.messenger.emit('egg-ready');
25
+ }
26
+ async onStop() {
27
+ // TODO flush egg logger and close it
28
+ }
29
+ };
30
+ __decorate([
31
+ (0, decorator_1.Inject)(),
32
+ __metadata("design:type", Object)
33
+ ], EggConfiguration.prototype, "baseDir", void 0);
34
+ __decorate([
35
+ (0, decorator_1.Inject)(),
36
+ __metadata("design:type", Object)
37
+ ], EggConfiguration.prototype, "appDir", void 0);
38
+ __decorate([
39
+ (0, decorator_1.App)(),
40
+ __metadata("design:type", Object)
41
+ ], EggConfiguration.prototype, "app", void 0);
42
+ __decorate([
43
+ (0, decorator_1.Inject)(),
44
+ __metadata("design:type", core_1.MidwayDecoratorService)
45
+ ], EggConfiguration.prototype, "decoratorService", void 0);
46
+ __decorate([
47
+ (0, decorator_1.Init)(),
48
+ __metadata("design:type", Function),
49
+ __metadata("design:paramtypes", []),
50
+ __metadata("design:returntype", void 0)
51
+ ], EggConfiguration.prototype, "init", null);
52
+ EggConfiguration = __decorate([
53
+ (0, decorator_1.Configuration)({
54
+ namespace: 'egg',
55
+ importConfigs: [
56
+ {
57
+ default: {
58
+ midwayLogger: {
59
+ clients: {
60
+ appLogger: {
61
+ fileLogName: 'midway-web.log',
62
+ aliasName: 'logger',
63
+ },
64
+ agentLogger: {
65
+ fileLogName: 'midway-agent.log',
66
+ },
67
+ },
68
+ },
69
+ egg: {
70
+ dumpConfig: true,
71
+ },
72
+ },
73
+ test: {
74
+ egg: {
75
+ plugins: {
76
+ 'egg-mock': {
77
+ enable: true,
78
+ package: 'egg-mock',
79
+ },
80
+ },
81
+ },
82
+ },
83
+ unittest: {
84
+ egg: {
85
+ plugins: {
86
+ 'egg-mock': {
87
+ enable: true,
88
+ package: 'egg-mock',
89
+ },
90
+ },
91
+ },
92
+ },
93
+ },
94
+ ],
95
+ })
96
+ ], EggConfiguration);
97
+ exports.EggConfiguration = EggConfiguration;
98
+ //# sourceMappingURL=configuration.js.map