@midwayjs/web 4.0.0-alpha.1 → 4.0.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/README.md CHANGED
@@ -9,4 +9,4 @@ Document: [https://midwayjs.org](https://midwayjs.org)
9
9
 
10
10
  ## License
11
11
 
12
- [MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))
12
+ [MIT]((https://github.com/midwayjs/midway/blob/master/LICENSE))
package/dist/cluster.js CHANGED
@@ -23,7 +23,7 @@ else {
23
23
  (0, core_1.prepareGlobalApplicationContext)({
24
24
  appDir,
25
25
  baseDir,
26
- ignore: ['**/app/extend/**', '**/app/public/**'],
26
+ // ignore: ['**/app/extend/**', '**/app/public/**'],
27
27
  });
28
28
  if (!isAgent) {
29
29
  debug('[egg]: run with egg-scripts in worker and init midway container complete');
@@ -15,6 +15,25 @@ exports.default = appInfo => {
15
15
  appLogger: {
16
16
  fileLogName: 'midway-web.log',
17
17
  aliasName: 'logger',
18
+ contextFormat: info => {
19
+ const ctx = info.ctx;
20
+ // format: '[$userId/$ip/$traceId/$use_ms $method $url]'
21
+ const userId = ctx.userId || '-';
22
+ const traceId = ctx.traceId ?? ctx.tracer?.traceId ?? '-';
23
+ const use = Date.now() - ctx.startTime;
24
+ const label = userId +
25
+ '/' +
26
+ ctx.ip +
27
+ '/' +
28
+ traceId +
29
+ '/' +
30
+ use +
31
+ 'ms ' +
32
+ ctx.method +
33
+ ' ' +
34
+ ctx.url;
35
+ return `${info.timestamp} ${info.LEVEL} ${info.pid} [${label}] ${info.message}`;
36
+ },
18
37
  },
19
38
  agentLogger: {
20
39
  fileLogName: 'midway-agent.log',
@@ -23,25 +42,6 @@ exports.default = appInfo => {
23
42
  });
24
43
  exports.egg = {
25
44
  dumpConfig: true,
26
- contextLoggerFormat: info => {
27
- const ctx = info.ctx;
28
- // format: '[$userId/$ip/$traceId/$use_ms $method $url]'
29
- const userId = ctx.userId || '-';
30
- const traceId = ctx.traceId ?? ctx.tracer?.traceId ?? '-';
31
- const use = Date.now() - ctx.startTime;
32
- const label = userId +
33
- '/' +
34
- ctx.ip +
35
- '/' +
36
- traceId +
37
- '/' +
38
- use +
39
- 'ms ' +
40
- ctx.method +
41
- ' ' +
42
- ctx.url;
43
- return `${info.timestamp} ${info.LEVEL} ${info.pid} [${label}] ${info.message}`;
44
- },
45
45
  queryParseMode: 'extended',
46
46
  };
47
47
  exports.pluginOverwrite = false;
@@ -15,6 +15,7 @@ const router_1 = require("@eggjs/router");
15
15
  const logger_1 = require("@midwayjs/logger");
16
16
  const path_1 = require("path");
17
17
  const util_1 = require("util");
18
+ const net_1 = require("net");
18
19
  const debug = (0, util_1.debuglog)('midway:debug');
19
20
  class EggControllerGenerator extends core_1.WebControllerGenerator {
20
21
  constructor(app, webRouterService) {
@@ -173,9 +174,9 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
173
174
  };
174
175
  // https config
175
176
  if (serverOptions.key && serverOptions.cert) {
176
- serverOptions.key = core_1.PathFileUtil.getFileContentSync(serverOptions.key);
177
- serverOptions.cert = core_1.PathFileUtil.getFileContentSync(serverOptions.cert);
178
- serverOptions.ca = core_1.PathFileUtil.getFileContentSync(serverOptions.ca);
177
+ serverOptions.key = core_1.PathFileUtils.getFileContentSync(serverOptions.key);
178
+ serverOptions.cert = core_1.PathFileUtils.getFileContentSync(serverOptions.cert);
179
+ serverOptions.ca = core_1.PathFileUtils.getFileContentSync(serverOptions.ca);
179
180
  process.env.MIDWAY_HTTP_SSL = 'true';
180
181
  if (serverOptions.http2) {
181
182
  this.server = require('http2').createSecureServer(serverOptions, this.app.callback());
@@ -200,7 +201,10 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
200
201
  this.getApplicationContext().registerObject(core_1.HTTP_SERVER_KEY, this.server);
201
202
  const eggConfig = this.configService.getConfiguration('egg');
202
203
  if (!this.isClusterMode && eggConfig) {
203
- const customPort = process.env.MIDWAY_HTTP_PORT ?? eggConfig.port;
204
+ let customPort = process.env.MIDWAY_HTTP_PORT ?? eggConfig.port;
205
+ if (customPort === 0) {
206
+ customPort = await getFreePort();
207
+ }
204
208
  if (customPort) {
205
209
  new Promise(resolve => {
206
210
  const args = [customPort];
@@ -221,15 +225,15 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
221
225
  if (name) {
222
226
  return this.app.loggers[name] || logger_1.loggers.getLogger(name);
223
227
  }
224
- return this.appLogger;
228
+ return this.loggerService.getLogger(this.frameworkLoggerName);
225
229
  }
226
230
  setContextLoggerClass() {
227
231
  // eslint-disable-next-line @typescript-eslint/no-this-alias
228
- const self = this;
232
+ const contextFormat = this.configService.getConfiguration('midwayLogger.clients.appLogger.contextFormat');
229
233
  class MidwayEggContextLogger extends logger_1.MidwayContextLogger {
230
234
  constructor(ctx, appLogger) {
231
235
  super(ctx, appLogger, {
232
- contextFormat: self.contextLoggerFormat,
236
+ contextFormat,
233
237
  });
234
238
  }
235
239
  }
@@ -260,4 +264,19 @@ __decorate([
260
264
  exports.MidwayWebFramework = MidwayWebFramework = __decorate([
261
265
  (0, core_1.Framework)()
262
266
  ], MidwayWebFramework);
267
+ async function getFreePort() {
268
+ return new Promise((resolve, reject) => {
269
+ const server = (0, net_1.createServer)();
270
+ server.listen(0, () => {
271
+ try {
272
+ const port = server.address().port;
273
+ server.close();
274
+ resolve(port);
275
+ }
276
+ catch (err) {
277
+ reject(err);
278
+ }
279
+ });
280
+ });
281
+ }
263
282
  //# sourceMappingURL=web.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/web",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-beta.2",
4
4
  "description": "Midway Web Framework for Egg.js",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
@@ -29,16 +29,16 @@
29
29
  "license": "MIT",
30
30
  "devDependencies": {
31
31
  "@midwayjs/logger": "^3.0.0",
32
- "@midwayjs/mock": "^4.0.0-alpha.1",
32
+ "@midwayjs/mock": "^4.0.0-beta.2",
33
33
  "@types/koa": "2.15.0",
34
34
  "dayjs": "1.11.13",
35
- "egg-logger": "3.6.0",
35
+ "egg-logger": "3.6.1",
36
36
  "egg-mock": "4.2.1",
37
- "egg-scripts": "3.0.1",
37
+ "egg-scripts": "3.1.0",
38
38
  "egg-socket.io": "4.1.6",
39
39
  "egg-view-nunjucks": "2.3.0",
40
40
  "fake-egg": "1.0.0",
41
- "fs-extra": "11.2.0",
41
+ "fs-extra": "11.3.0",
42
42
  "is-type-of": "^2.1.0",
43
43
  "mm": "3.4.0",
44
44
  "mz-modules": "^2.1.0",
@@ -49,13 +49,13 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@eggjs/router": "^2.0.0",
52
- "@midwayjs/core": "^4.0.0-alpha.1",
52
+ "@midwayjs/core": "^4.0.0-beta.2",
53
53
  "egg": "^2.28.0",
54
54
  "egg-cluster": "^1.27.1",
55
55
  "egg-path-matching": "^2.1.0",
56
56
  "find-up": "5.0.0",
57
57
  "mkdirp": "1.0.4",
58
- "qs": "6.13.1"
58
+ "qs": "6.14.0"
59
59
  },
60
60
  "author": "Harry Chen <czy88840616@gmail.com>",
61
61
  "repository": {
@@ -63,7 +63,7 @@
63
63
  "url": "https://github.com/midwayjs/midway.git"
64
64
  },
65
65
  "engines": {
66
- "node": ">=12"
66
+ "node": ">=20"
67
67
  },
68
- "gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
68
+ "gitHead": "53bfef4c5279da5f09025e4610bdbf64f94f60bd"
69
69
  }