egg 3.30.0 → 3.31.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/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/index.d.ts +16 -4
- package/lib/core/fetch_factory.js +37 -0
- package/lib/core/httpclient_next.js +2 -2
- package/lib/egg.js +7 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ English | [简体中文](./README.zh-CN.md)
|
|
|
4
4
|
<img src="site/public/assets/egg-banner.png" />
|
|
5
5
|
</div>
|
|
6
6
|
|
|
7
|
-
[](https://npmjs.
|
|
7
|
+
[](https://www.npmjs.com/package/egg/v/release-3.x)
|
|
8
8
|
[](http://packagequality.com/#?package=egg)
|
|
9
9
|
[](https://npmjs.org/package/egg)
|
|
10
10
|
[](https://app.fossa.com/projects/git%2Bgithub.com%2Feggjs%2Fegg?ref=badge_shield)
|
|
@@ -37,7 +37,7 @@ $ open http://localhost:7001
|
|
|
37
37
|
|
|
38
38
|
## Documentations
|
|
39
39
|
|
|
40
|
-
- [Documentations](https://eggjs.org/
|
|
40
|
+
- [Documentations](https://v3.eggjs.org/)
|
|
41
41
|
- [Plugins](https://github.com/search?q=topic%3Aegg-plugin&type=Repositories)
|
|
42
42
|
- [Frameworks](https://github.com/search?q=topic%3Aegg-framework&type=Repositories)
|
|
43
43
|
- [Examples](https://github.com/eggjs/examples)
|
package/README.zh-CN.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<img src="site/public/assets/egg-banner.png" />
|
|
5
5
|
</div>
|
|
6
6
|
|
|
7
|
-
[](https://npmjs.
|
|
7
|
+
[](https://www.npmjs.com/package/egg/v/release-3.x)
|
|
8
8
|
[](http://packagequality.com/#?package=egg)
|
|
9
9
|
[](https://npmjs.org/package/egg)
|
|
10
10
|
|
|
@@ -34,7 +34,7 @@ $ open http://localhost:7001
|
|
|
34
34
|
|
|
35
35
|
## 文档
|
|
36
36
|
|
|
37
|
-
- [官方文档](https://eggjs.org/zh-
|
|
37
|
+
- [官方文档](https://v3.eggjs.org/zh-CN/)
|
|
38
38
|
- [插件列表](https://github.com/search?q=topic%3Aegg-plugin&type=Repositories)
|
|
39
39
|
- [框架列表](https://github.com/search?q=topic%3Aegg-framework&type=Repositories)
|
|
40
40
|
- [官方示例](https://github.com/eggjs/examples)
|
package/index.d.ts
CHANGED
|
@@ -19,10 +19,14 @@ import {
|
|
|
19
19
|
HttpClientResponse as HttpClientResponseOld,
|
|
20
20
|
} from 'urllib';
|
|
21
21
|
import {
|
|
22
|
-
RequestURL
|
|
23
|
-
RequestOptions
|
|
24
|
-
HttpClientResponse,
|
|
22
|
+
RequestURL,
|
|
23
|
+
RequestOptions,
|
|
24
|
+
HttpClientResponse as HttpClientResponseNext,
|
|
25
25
|
} from 'urllib-next';
|
|
26
|
+
import {
|
|
27
|
+
FetchFactory,
|
|
28
|
+
fetch,
|
|
29
|
+
} from 'urllib4';
|
|
26
30
|
import {
|
|
27
31
|
EggCoreBase,
|
|
28
32
|
FileLoaderOption,
|
|
@@ -60,7 +64,9 @@ declare module 'egg' {
|
|
|
60
64
|
// return await app.httpclient.request(url, options);
|
|
61
65
|
// }
|
|
62
66
|
// ```
|
|
63
|
-
export
|
|
67
|
+
export type HttpClientRequestURL = RequestURL;
|
|
68
|
+
export type HttpClientRequestOptions = RequestOptions;
|
|
69
|
+
export type HttpClientResponse<T = any> = HttpClientResponseNext<T>;
|
|
64
70
|
// Compatible with both urllib@2 and urllib@3 RequestOptions to request
|
|
65
71
|
export interface EggHttpClient extends EventEmitter {
|
|
66
72
|
request<T = any>(url: HttpClientRequestURL): Promise<HttpClientResponseOld<T> | HttpClientResponse<T>>;
|
|
@@ -587,6 +593,12 @@ declare module 'egg' {
|
|
|
587
593
|
*/
|
|
588
594
|
httpclient: EggHttpClient;
|
|
589
595
|
|
|
596
|
+
/**
|
|
597
|
+
* node fetch
|
|
598
|
+
*/
|
|
599
|
+
FetchFactory: FetchFactory;
|
|
600
|
+
fetch: typeof fetch,
|
|
601
|
+
|
|
590
602
|
/**
|
|
591
603
|
* Logger for Application, wrapping app.coreLogger with context infomation
|
|
592
604
|
*
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const debug = require('util').debuglog('egg:lib:core:fetch_factory');
|
|
2
|
+
|
|
3
|
+
const mainNodejsVersion = parseInt(process.versions.node.split('.')[0]);
|
|
4
|
+
let FetchFactory;
|
|
5
|
+
let safeFetch;
|
|
6
|
+
let ssrfFetchFactory;
|
|
7
|
+
|
|
8
|
+
if (mainNodejsVersion >= 20) {
|
|
9
|
+
// urllib@4 only works on Node.js >= 20
|
|
10
|
+
try {
|
|
11
|
+
const urllib4 = require('urllib4');
|
|
12
|
+
FetchFactory = urllib4.FetchFactory;
|
|
13
|
+
debug('urllib4 enable');
|
|
14
|
+
|
|
15
|
+
safeFetch = function safeFetch(url, init) {
|
|
16
|
+
if (!ssrfFetchFactory) {
|
|
17
|
+
const ssrfConfig = this.config.security.ssrf;
|
|
18
|
+
const clientOptions = {};
|
|
19
|
+
if (ssrfConfig?.checkAddress) {
|
|
20
|
+
clientOptions.checkAddress = ssrfConfig.checkAddress;
|
|
21
|
+
} else {
|
|
22
|
+
this.logger.warn('[egg-security] please configure `config.security.ssrf` first');
|
|
23
|
+
}
|
|
24
|
+
ssrfFetchFactory = new FetchFactory();
|
|
25
|
+
ssrfFetchFactory.setClientOptions(clientOptions);
|
|
26
|
+
}
|
|
27
|
+
return ssrfFetchFactory.fetch(url, init);
|
|
28
|
+
};
|
|
29
|
+
} catch (err) {
|
|
30
|
+
debug('require urllib4 error: %s', err);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
FetchFactory,
|
|
36
|
+
safeFetch,
|
|
37
|
+
};
|
|
@@ -5,8 +5,8 @@ const SSRF_HTTPCLIENT = Symbol('SSRF_HTTPCLIENT');
|
|
|
5
5
|
|
|
6
6
|
const mainNodejsVersion = parseInt(process.versions.node.split('.')[0]);
|
|
7
7
|
let HttpClient;
|
|
8
|
-
if (mainNodejsVersion >=
|
|
9
|
-
// urllib@4 only works on Node.js >=
|
|
8
|
+
if (mainNodejsVersion >= 20) {
|
|
9
|
+
// urllib@4 only works on Node.js >= 20
|
|
10
10
|
try {
|
|
11
11
|
HttpClient = require('urllib4').HttpClient;
|
|
12
12
|
debug('urllib4 enable');
|
package/lib/egg.js
CHANGED
|
@@ -14,6 +14,7 @@ const Messenger = require('./core/messenger');
|
|
|
14
14
|
const DNSCacheHttpClient = require('./core/dnscache_httpclient');
|
|
15
15
|
const HttpClient = require('./core/httpclient');
|
|
16
16
|
const HttpClientNext = require('./core/httpclient_next');
|
|
17
|
+
const { FetchFactory, safeFetch } = require('./core/fetch_factory');
|
|
17
18
|
const createLoggers = require('./core/logger');
|
|
18
19
|
const Singleton = require('./core/singleton');
|
|
19
20
|
const utils = require('./core/utils');
|
|
@@ -51,6 +52,12 @@ class EggApplication extends EggCore {
|
|
|
51
52
|
this.ContextHttpClient = ContextHttpClient;
|
|
52
53
|
this.HttpClient = HttpClient;
|
|
53
54
|
this.HttpClientNext = HttpClientNext;
|
|
55
|
+
this.FetchFactory = FetchFactory;
|
|
56
|
+
if (FetchFactory) {
|
|
57
|
+
this.FetchFactory.setClientOptions();
|
|
58
|
+
this.fetch = FetchFactory.fetch;
|
|
59
|
+
this.safeFetch = safeFetch.bind(this);
|
|
60
|
+
}
|
|
54
61
|
|
|
55
62
|
this.loader.loadConfig();
|
|
56
63
|
|