You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: LICENSE
+93
Original file line number
Diff line number
Diff line change
@@ -19,3 +19,96 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
SOFTWARE.
22
+
23
+
---
24
+
25
+
https://github.com/node-fetch/node-fetch
26
+
27
+
The MIT License (MIT)
28
+
29
+
Copyright (c) 2016 - 2020 Node Fetch Team
30
+
31
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
32
+
33
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
34
+
35
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36
+
37
+
---
38
+
39
+
https://github.com/mysticatea/abort-controller
40
+
41
+
MIT License
42
+
43
+
Copyright (c) 2017 Toru Nagashima
44
+
45
+
Permission is hereby granted, free of charge, to any person obtaining a copy
46
+
of this software and associated documentation files (the "Software"), to deal
47
+
in the Software without restriction, including without limitation the rights
48
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
49
+
copies of the Software, and to permit persons to whom the Software is
50
+
furnished to do so, subject to the following conditions:
51
+
52
+
The above copyright notice and this permission notice shall be included in all
53
+
copies or substantial portions of the Software.
54
+
55
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
58
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
A redistribution of [node-fetch v3](https://github.com/node-fetch/node-fetch) for better backward and forward compatibility.
10
+
A redistribution of [node-fetch v3](https://github.com/node-fetch/node-fetch)(+ more!) for better backward and forward compatibility.
10
11
11
12
**Why this package?**
12
13
13
14
- We can no longer `require('node-fetch')` with latest version. This stopped popular libraries from upgrading and dependency conflicts between `node-fetch@2` and `node-fetch@3`.
14
15
- With upcoming versions of Node.js, native `fetch` is being supported. We are prepared for native fetch support using this package yet keep supporting older Node versions.
16
+
- With introduction of native fetch to Node.js via [undici](https://github.com/nodejs/undici) there is no easy way to support http proxies!
15
17
16
18
**Features:**
17
19
@@ -25,6 +27,8 @@ A redistribution of [node-fetch v3](https://github.com/node-fetch/node-fetch) fo
25
27
26
28
✅ Polyfill support for Node.js
27
29
30
+
✅ Compact and simple proxy supporting both Node.js versions without native fetch using [HTTP Agent](https://github.com/TooTallNate/proxy-agents/tree/main/packages/proxy-agent) and versions with native fetch using [Undici Proxy Agent](https://undici.nodejs.org/#/docs/api/ProxyAgent)
31
+
28
32
## Usage
29
33
30
34
Install `node-fetch-native` dependency:
@@ -44,22 +48,65 @@ You can now either import or require the dependency:
Node.js has no built-in support for HTTP Proxies for fetch ([see nodejs/undici#1650](https://github.com/nodejs/undici/issues/1650) and [nodejs/node#8381](https://github.com/nodejs/node/issues/8381))
86
+
87
+
This package bundles a compact and simple proxy supported for both Node.js versions without native fetch using [HTTP Agent](https://github.com/TooTallNate/proxy-agents/tree/main/packages/proxy-agent) and versions with native fetch using [Undici Proxy Agent](https://undici.nodejs.org/#/docs/api/ProxyAgent).
88
+
89
+
**Usage:**
90
+
91
+
```ts
92
+
import { fetch } from"node-fetch-native"; // or use global fetch
`createProxy` returns an object with `agent` for older Node.js version and `dispatcher` keys for newer Node.js versions with undici and native fetch.
105
+
106
+
If no `url` option is provided, `HTTPS_PROXY` or `HTTP_PROXY` value will be used and if they also are not set, both `agent` and `dispatcher` values will be undefined.
107
+
108
+
**Note:** Using export conditions, this utility works in Node.js and for other runtimes, it will simply return an stubbed version as most of other runtimes now support http proxy out of the box!
109
+
63
110
## Force using non-native version
64
111
65
112
Sometimes you want to explicitly use none native (`node-fetch`) implementation of `fetch` in case of issues with native/polyfill version of `globalThis.fetch` with Node.js or runtime environment.
@@ -77,10 +124,10 @@ Using the polyfill method, we can once ensure global fetch is available in the e
77
124
78
125
```js
79
126
// ESM
80
-
import'node-fetch-native/polyfill'
127
+
import"node-fetch-native/polyfill";
81
128
82
129
// CJS
83
-
require('node-fetch-native/polyfill')
130
+
require("node-fetch-native/polyfill");
84
131
85
132
// You can now use fetch() without any import!
86
133
```
@@ -137,20 +184,16 @@ Made with 💛
137
184
[node-fetch is published under the MIT license](https://github.com/node-fetch/node-fetch/blob/main/LICENSE.md)
0 commit comments