egg 3.30.1 → 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 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
- [![NPM version](https://img.shields.io/npm/v/egg.svg?style=flat-square)](https://npmjs.org/package/egg)
7
+ [![NPM version](https://img.shields.io/npm/v/egg/release-3.x.svg?style=flat-square)](https://www.npmjs.com/package/egg/v/release-3.x)
8
8
  [![NPM quality](http://npm.packagequality.com/shield/egg.svg?style=flat-square)](http://packagequality.com/#?package=egg)
9
9
  [![NPM download](https://img.shields.io/npm/dm/egg.svg?style=flat-square)](https://npmjs.org/package/egg)
10
10
  [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Feggjs%2Fegg.svg?type=shield)](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/en/index.html)
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
- [![NPM version](https://img.shields.io/npm/v/egg.svg?style=flat-square)](https://npmjs.org/package/egg)
7
+ [![NPM version](https://img.shields.io/npm/v/egg/release-3.x.svg?style=flat-square)](https://www.npmjs.com/package/egg/v/release-3.x)
8
8
  [![NPM quality](http://npm.packagequality.com/shield/egg.svg?style=flat-square)](http://packagequality.com/#?package=egg)
9
9
  [![NPM download](https://img.shields.io/npm/dm/egg.svg?style=flat-square)](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-cn/)
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
@@ -23,6 +23,10 @@ import {
23
23
  RequestOptions,
24
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,
@@ -589,6 +593,12 @@ declare module 'egg' {
589
593
  */
590
594
  httpclient: EggHttpClient;
591
595
 
596
+ /**
597
+ * node fetch
598
+ */
599
+ FetchFactory: FetchFactory;
600
+ fetch: typeof fetch,
601
+
592
602
  /**
593
603
  * Logger for Application, wrapping app.coreLogger with context infomation
594
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 >= 18) {
9
- // urllib@4 only works on Node.js >= 18
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
 
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "egg",
3
- "version": "3.30.1",
3
+ "version": "3.31.0",
4
4
  "publishConfig": {
5
- "tag": "latest",
5
+ "tag": "release-3.x",
6
6
  "access": "public"
7
7
  },
8
8
  "description": "A web framework's framework for Node.js",