egg 2.30.0 → 2.33.1

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/History.md CHANGED
@@ -1,5 +1,45 @@
1
+
2
+ 2.33.1 / 2021-12-07
3
+ ==================
4
+
5
+ **features**
6
+ * [[`18dcadc1c`](http://github.com/eggjs/egg/commit/18dcadc1cf6c9837de605916a0d8b161a63e7218)] - feat: meta middleware x-readtime support performanceStarttime (#4827) (fengmk2 <<fengmk2@gmail.com>>)
7
+
8
+ **others**
9
+ * [[`8659d4bc3`](http://github.com/eggjs/egg/commit/8659d4bc37e0652d66d04d2e5504fdc0ef2f7f7d)] - docs: update contributors (#4826) (Suyi <<thonatos.yang@gmail.com>>)
10
+ * [[`4d18732c7`](http://github.com/eggjs/egg/commit/4d18732c79e44a84140df05e879b8b5f569c2b4b)] - chore: remove @types/urllib from autod (fengmk2 <<fengmk2@gmail.com>>)
11
+
12
+ 2.33.0 / 2021-12-06
13
+ ==================
14
+
15
+ **features**
16
+ * [[`0f6589e1d`](http://github.com/eggjs/egg/commit/0f6589e1dc9e538434eb1580327556d5aa264822)] - feat: support better logger timer in precise milliseconds (#4806) (fengmk2 <<fengmk2@gmail.com>>)
1
17
  # History
2
18
 
19
+ ## 2021-11-15, Version 2.32.0 @atian25
20
+
21
+ ### Notable Changes
22
+
23
+ * **features**
24
+ * handle ENETUNREACH error on httpclient
25
+
26
+ ### Commits
27
+
28
+ * [[`189c47804`](http://github.com/eggjs/egg/commit/189c478048d820b7b1a6ba6e8bce3444604876ff)] - feat: handle ENETUNREACH error on httpclient (#4792) (fengmk2 <<fengmk2@gmail.com>>)
29
+
30
+
31
+ ## 2021-10-18, Version 2.31.0 @killagu
32
+
33
+ ### Notable Changes
34
+
35
+ * **typing**
36
+ * support ssrf typing in config
37
+
38
+ ### Commits
39
+
40
+ * [[`debfda7ab`](https://github.com/eggjs/egg/commit/debfda7ab38f4893b6f122abfbf3e5288af1441e)] - feat(config): support ssrf field in security config. (#4778) (Jasin Yip <<yejunxing@gmail.com>>)
41
+
42
+
3
43
  ## 2021-08-09, Version 2.30.0 @mansonchor
4
44
 
5
45
  ### Notable Changes
package/README.md CHANGED
@@ -42,7 +42,7 @@ $ open http://localhost:7001
42
42
 
43
43
  ## Contributors
44
44
 
45
- [![contributors](https://badges.implements.io/api/contributors?org=eggjs&repo=egg&width=1280&size=48&padding=6&type=jpeg)](https://github.com/eggjs/egg/graphs/contributors)
45
+ [![contributors](https://ergatejs.implements.io/badges/contributors/eggjs/egg.png)](https://github.com/eggjs/egg/graphs/contributors)
46
46
 
47
47
  ## How to Contribute
48
48
 
package/README.zh-CN.md CHANGED
@@ -39,7 +39,7 @@ $ open http://localhost:7001
39
39
 
40
40
  ## 贡献者
41
41
 
42
- [![contributors](https://badges.implements.io/api/contributors?org=eggjs&repo=egg&width=1280&size=48&padding=6&type=jpeg)](https://github.com/eggjs/egg/graphs/contributors)
42
+ [![contributors](https://ergatejs.implements.io/badges/contributors/eggjs/egg.png)](https://github.com/eggjs/egg/graphs/contributors)
43
43
 
44
44
  ## 贡献代码
45
45
 
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const { performance } = require('perf_hooks');
3
4
  const delegate = require('delegates');
4
5
  const { assign } = require('utility');
5
6
  const eggUtils = require('egg-core').utils;
@@ -219,7 +220,7 @@ const proto = module.exports = {
219
220
  // e.g.: https://github.com/eggjs/egg-mock/pull/78
220
221
  _runInBackground(scope) {
221
222
  const ctx = this;
222
- const start = Date.now();
223
+ const start = performance.now();
223
224
  /* istanbul ignore next */
224
225
  const taskName = scope._name || scope.name || eggUtils.getCalleeFromStack(true);
225
226
  // use setImmediate to ensure all sync logic will run async
@@ -227,11 +228,13 @@ const proto = module.exports = {
227
228
  // use app.toAsyncFunction to support both generator function and async function
228
229
  .then(() => ctx.app.toAsyncFunction(scope)(ctx))
229
230
  .then(() => {
230
- ctx.coreLogger.info('[egg:background] task:%s success (%dms)', taskName, Date.now() - start);
231
+ ctx.coreLogger.info('[egg:background] task:%s success (%dms)',
232
+ taskName, Math.floor((performance.now() - start) * 1000) / 1000);
231
233
  })
232
234
  .catch(err => {
233
235
  // background task process log
234
- ctx.coreLogger.info('[egg:background] task:%s fail (%dms)', taskName, Date.now() - start);
236
+ ctx.coreLogger.info('[egg:background] task:%s fail (%dms)',
237
+ taskName, Math.floor((performance.now() - start) * 1000) / 1000);
235
238
 
236
239
  // emit error when promise catch, and set err.runInBackground flag
237
240
  err.runInBackground = true;
@@ -4,6 +4,7 @@
4
4
 
5
5
  'use strict';
6
6
 
7
+ const { performance } = require('perf_hooks');
7
8
  const semver = require('semver');
8
9
 
9
10
  module.exports = options => {
@@ -16,7 +17,11 @@ module.exports = options => {
16
17
  }
17
18
  await next();
18
19
  // total response time header
19
- ctx.set('x-readtime', Date.now() - ctx.starttime);
20
+ if (ctx.performanceStarttime) {
21
+ ctx.set('x-readtime', Math.floor((performance.now() - ctx.performanceStarttime) * 1000) / 1000);
22
+ } else {
23
+ ctx.set('x-readtime', Date.now() - ctx.starttime);
24
+ }
20
25
 
21
26
  // try to support Keep-Alive Header when < 14.8.0
22
27
  const server = ctx.app.server;
@@ -249,6 +249,8 @@ module.exports = appInfo => {
249
249
  * @property {String} coreLogName - file name of coreLogger
250
250
  * @property {String} agentLogName - file name of agent worker log
251
251
  * @property {Object} coreLogger - custom config of coreLogger
252
+ * @property {Boolean} allowDebugAtProd - allow debug log at prod, defaults to false
253
+ * @property {Boolean} enablePerformanceTimer - using performance.now() timer instead of Date.now() for more more precise milliseconds, defaults to false. e.g.: logger will set 1.456ms instead of 1ms.
252
254
  */
253
255
  config.logger = {
254
256
  dir: path.join(appInfo.root, 'logs', appInfo.name),
@@ -265,6 +267,7 @@ module.exports = appInfo => {
265
267
  errorLogName: 'common-error.log',
266
268
  coreLogger: {},
267
269
  allowDebugAtProd: false,
270
+ enablePerformanceTimer: false,
268
271
  };
269
272
 
270
273
  /**
package/index.d.ts CHANGED
@@ -217,10 +217,12 @@ declare module 'egg' {
217
217
  export interface EggLoggerConfig extends RemoveSpecProp<EggLoggersOptions, 'type'> {
218
218
  /** custom config of coreLogger */
219
219
  coreLogger?: Partial<EggLoggerOptions>;
220
- /** allow debug log at prod, defaults to true */
220
+ /** allow debug log at prod, defaults to `false` */
221
221
  allowDebugAtProd?: boolean;
222
222
  /** disable logger console after app ready. defaults to `false` on local and unittest env, others is `true`. */
223
223
  disableConsoleAfterReady?: boolean;
224
+ /** using performance.now() timer instead of Date.now() for more more precise milliseconds, defaults to `false`. e.g.: logger will set 1.456ms instead of 1ms. */
225
+ enablePerformanceTimer?: boolean;
224
226
  }
225
227
 
226
228
  /** Custom Loader Configuration */
@@ -329,7 +331,8 @@ declare module 'egg' {
329
331
  * @property {String} coreLogName - file name of coreLogger
330
332
  * @property {String} agentLogName - file name of agent worker log
331
333
  * @property {Object} coreLogger - custom config of coreLogger
332
- * @property {Boolean} allowDebugAtProd - allow debug log at prod, defaults to true
334
+ * @property {Boolean} allowDebugAtProd - allow debug log at prod, defaults to false
335
+ * @property {Boolean} enablePerformanceTimer - using performance.now() timer instead of Date.now() for more more precise milliseconds, defaults to false. e.g.: logger will set 1.456ms instead of 1ms.
333
336
  */
334
337
  logger: EggLoggerConfig;
335
338
 
@@ -466,6 +469,10 @@ declare module 'egg' {
466
469
  protocolWhiteList: string[];
467
470
  defaultMiddleware: string;
468
471
  csrf: any;
472
+ ssrf: {
473
+ ipBlackList: string[];
474
+ checkAddress?(ip: string): boolean;
475
+ };
469
476
  xframe: {
470
477
  enable: boolean;
471
478
  value: 'SAMEORIGIN' | 'DENY' | 'ALLOW-FROM';
@@ -920,6 +927,11 @@ declare module 'egg' {
920
927
  */
921
928
  starttime: number;
922
929
 
930
+ /**
931
+ * Request start timer using `performance.now()`
932
+ */
933
+ performanceStarttime?: number;
934
+
923
935
  /**
924
936
  * http request helper base on httpclient, it will auto save httpclient log.
925
937
  * Keep the same api with httpclient.request(url, args).
@@ -4,6 +4,13 @@ const Agent = require('agentkeepalive');
4
4
  const HttpsAgent = require('agentkeepalive').HttpsAgent;
5
5
  const urllib = require('urllib');
6
6
  const ms = require('humanize-ms');
7
+ const { FrameworkBaseError } = require('egg-errors');
8
+
9
+ class HttpClientError extends FrameworkBaseError {
10
+ get module() {
11
+ return 'httpclient';
12
+ }
13
+ }
7
14
 
8
15
  class HttpClient extends urllib.HttpClient2 {
9
16
  constructor(app) {
@@ -42,7 +49,13 @@ class HttpClient extends urllib.HttpClient2 {
42
49
  }
43
50
 
44
51
  // the Promise style
45
- return super.request(url, args);
52
+ return super.request(url, args)
53
+ .catch(err => {
54
+ if (err.code === 'ENETUNREACH') {
55
+ throw HttpClientError.create(err.message, err.code);
56
+ }
57
+ throw err;
58
+ });
46
59
  }
47
60
 
48
61
  curl(url, args, callback) {
package/lib/egg.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const { performance } = require('perf_hooks');
3
4
  const path = require('path');
4
5
  const fs = require('fs');
5
6
  const ms = require('ms');
@@ -547,6 +548,14 @@ class EggApplication extends EggCore {
547
548
  * @member {Number} Context#starttime
548
549
  */
549
550
  context.starttime = Date.now();
551
+
552
+ if (this.config.logger.enablePerformanceTimer) {
553
+ /**
554
+ * Request start timer using `performance.now()`
555
+ * @member {Number} Context#performanceStarttime
556
+ */
557
+ context.performanceStarttime = performance.now();
558
+ }
550
559
  return context;
551
560
  }
552
561
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "egg",
3
- "version": "2.30.0",
3
+ "version": "2.33.1",
4
4
  "description": "A web framework's framework for Node.js",
5
5
  "keywords": [
6
6
  "web",
@@ -27,6 +27,7 @@
27
27
  "egg-cookies": "^2.3.0",
28
28
  "egg-core": "^4.18.0",
29
29
  "egg-development": "^2.4.2",
30
+ "egg-errors": "^2.3.0",
30
31
  "egg-i18n": "^2.0.0",
31
32
  "egg-jsonp": "^2.0.0",
32
33
  "egg-logger": "^2.3.2",
@@ -115,7 +116,7 @@
115
116
  "url": "https://github.com/eggjs/egg.git"
116
117
  },
117
118
  "engines": {
118
- "node": ">= 8.0.0"
119
+ "node": ">= 8.5.0"
119
120
  },
120
121
  "license": "MIT"
121
122
  }