egg 2.29.4 → 2.33.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/History.md +52 -0
- package/app/extend/context.js +6 -3
- package/config/config.default.js +3 -0
- package/index.d.ts +14 -2
- package/lib/core/dnscache_httpclient.js +9 -0
- package/lib/core/httpclient.js +14 -1
- package/lib/egg.js +9 -0
- package/package.json +3 -2
package/History.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
2.33.0 / 2021-12-06
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
**features**
|
|
6
|
+
* [[`0f6589e1d`](http://github.com/eggjs/egg/commit/0f6589e1dc9e538434eb1580327556d5aa264822)] - feat: support better logger timer in precise milliseconds (#4806) (fengmk2 <<fengmk2@gmail.com>>)
|
|
1
7
|
# History
|
|
2
8
|
|
|
9
|
+
## 2021-11-15, Version 2.32.0 @atian25
|
|
10
|
+
|
|
11
|
+
### Notable Changes
|
|
12
|
+
|
|
13
|
+
* **features**
|
|
14
|
+
* handle ENETUNREACH error on httpclient
|
|
15
|
+
|
|
16
|
+
### Commits
|
|
17
|
+
|
|
18
|
+
* [[`189c47804`](http://github.com/eggjs/egg/commit/189c478048d820b7b1a6ba6e8bce3444604876ff)] - feat: handle ENETUNREACH error on httpclient (#4792) (fengmk2 <<fengmk2@gmail.com>>)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## 2021-10-18, Version 2.31.0 @killagu
|
|
22
|
+
|
|
23
|
+
### Notable Changes
|
|
24
|
+
|
|
25
|
+
* **typing**
|
|
26
|
+
* support ssrf typing in config
|
|
27
|
+
|
|
28
|
+
### Commits
|
|
29
|
+
|
|
30
|
+
* [[`debfda7ab`](https://github.com/eggjs/egg/commit/debfda7ab38f4893b6f122abfbf3e5288af1441e)] - feat(config): support ssrf field in security config. (#4778) (Jasin Yip <<yejunxing@gmail.com>>)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## 2021-08-09, Version 2.30.0 @mansonchor
|
|
34
|
+
|
|
35
|
+
### Notable Changes
|
|
36
|
+
|
|
37
|
+
* **features**
|
|
38
|
+
* support disableDNSCache in one request even though config set to `enableDNSCache: true`
|
|
39
|
+
|
|
40
|
+
* **docs**
|
|
41
|
+
* update ts docs, add missing zh-CN doc
|
|
42
|
+
* typo fix
|
|
43
|
+
|
|
44
|
+
### Commits
|
|
45
|
+
|
|
46
|
+
* [[`13dd55076`](https://github.com/eggjs/egg.git/commit/13dd5507694a57a11e12d1ac6f71ba4a562d88c0)] - feat: support disableDNSCache by request args handle (#4728) (mansonchor.github.com <<mansonchor1987@gmail.com>>)
|
|
47
|
+
* [[`1b4fde454`](https://github.com/eggjs/egg.git/commit/1b4fde454d2d61200a8b066ba841ad6d81b5b69d)] - unittest: rename and remove some useless tests (#4705) (Maledong <<maledong_public@foxmail.com>>)
|
|
48
|
+
* [[`156980d36`](https://github.com/eggjs/egg.git/commit/156980d369570531c1ef9cf842f02f513b56fe4a)] - doc: Typo fixture (#4707) (Maledong <<maledong_public@foxmail.com>>)
|
|
49
|
+
* [[`27aa49b59`](https://github.com/eggjs/egg.git/commit/27aa49b5945f08fa6b636479cf4cba7822e3af2d)] - doc: Typo fixture:「,」->「,」 (#4708) (陈煮酒 <<501205587@qq.com>>)
|
|
50
|
+
* [[`1f02a8d45`](https://github.com/eggjs/egg.git/commit/1f02a8d4560ca3334425e646c1ac87226aba3a63)] - doc: Add the missing zh-CN trans for typescript (#4703) (Maledong <<52018749+MaledongGit@users.noreply.github.com>>)
|
|
51
|
+
* [[`f5cf0d965`](https://github.com/eggjs/egg.git/commit/f5cf0d965fa4077da10e87f070e113496077872c)] - doc: "登陆" should be "登录" (#4697) (HOU Ce <<594965698@qq.com>>)
|
|
52
|
+
* [[`750558400`](https://github.com/eggjs/egg.git/commit/750558400e3bd5f39658dfcbedd4af7bc0bdda2a)] - docs: update ts docs (#4666) (吖猩 <<whxaxes@gmail.com>>)
|
|
53
|
+
* [[`93d2b04b9`](https://github.com/eggjs/egg.git/commit/93d2b04b985145f27a39335300a78002a61da2a8)] - docs: fix loaderUpdate.md didReady example (#4652) (shadyzoz <<shadyzoz@icloud.com>>)
|
|
54
|
+
|
|
3
55
|
## 2021-04-13, Version 2.29.4 @popomore
|
|
4
56
|
|
|
5
57
|
### Notable Changes
|
package/app/extend/context.js
CHANGED
|
@@ -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 =
|
|
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)',
|
|
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)',
|
|
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;
|
package/config/config.default.js
CHANGED
|
@@ -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
|
|
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
|
|
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).
|
|
@@ -27,6 +27,11 @@ class DNSCacheHttpClient extends HttpClient {
|
|
|
27
27
|
// the callback style
|
|
28
28
|
if (callback) {
|
|
29
29
|
this.app.deprecate('[dnscache_httpclient] We now support async for this function, so callback isn\'t recommended.');
|
|
30
|
+
// disable dns cache in request by args handle
|
|
31
|
+
if (args && args.enableDNSCache === false) {
|
|
32
|
+
super.request(url, args, callback);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
30
35
|
this[DNSLOOKUP](url, args)
|
|
31
36
|
.then(result => {
|
|
32
37
|
return super.request(result.url, result.args);
|
|
@@ -38,6 +43,10 @@ class DNSCacheHttpClient extends HttpClient {
|
|
|
38
43
|
|
|
39
44
|
// the Promise style
|
|
40
45
|
return (async () => {
|
|
46
|
+
// disable dns cache in request by args handle
|
|
47
|
+
if (args && args.enableDNSCache === false) {
|
|
48
|
+
return super.request(url, args);
|
|
49
|
+
}
|
|
41
50
|
const result = await this[DNSLOOKUP](url, args);
|
|
42
51
|
return super.request(result.url, result.args);
|
|
43
52
|
})();
|
package/lib/core/httpclient.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "2.33.0",
|
|
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.
|
|
119
|
+
"node": ">= 8.5.0"
|
|
119
120
|
},
|
|
120
121
|
"license": "MIT"
|
|
121
122
|
}
|