@@ -8,45 +8,6 @@ import { HttpsProxyAgent } from "https-proxy-agent";
8
8
import type { ProxyOptions } from "../proxy" ;
9
9
import { fetch as _fetch } from "node-fetch-native" ;
10
10
11
- export function createProxy ( opts : ProxyOptions = { } ) {
12
- const uri =
13
- opts . url ||
14
- process . env . https_proxy ||
15
- process . env . http_proxy ||
16
- process . env . HTTPS_PROXY ||
17
- process . env . HTTP_PROXY ;
18
-
19
- if ( ! uri ) {
20
- return {
21
- agent : undefined ,
22
- dispatcher : undefined ,
23
- } ;
24
- }
25
-
26
- const _noProxy = opts . noProxy || process . env . no_proxy || process . env . NO_PROXY ;
27
- const noProxy = typeof _noProxy === "string" ? _noProxy . split ( "," ) : _noProxy ;
28
-
29
- const nodeAgent = new NodeProxyAgent ( { uri, noProxy } ) ;
30
-
31
- // https://undici.nodejs.org/#/docs/api/ProxyAgent
32
- const undiciAgent = new UndiciProxyAgent ( {
33
- uri,
34
- noProxy,
35
- } ) ;
36
-
37
- return {
38
- agent : nodeAgent ,
39
- dispatcher : undiciAgent ,
40
- } ;
41
- }
42
-
43
- export function createFetch ( proxyOptions : ProxyOptions = { } ) {
44
- const proxy = createProxy ( proxyOptions ) ;
45
- return ( url , fetchOptions ) => _fetch ( url , { ...proxy , ...fetchOptions } ) ;
46
- }
47
-
48
- export const fetch = createFetch ( { } ) ;
49
-
50
11
// ----------------------------------------------
51
12
// Utils
52
13
// ----------------------------------------------
@@ -170,3 +131,46 @@ class NodeProxyAgent extends Agent {
170
131
super . destroy ( ) ;
171
132
}
172
133
}
134
+
135
+ // ----------------------------------------------
136
+ // Main exports
137
+ // ----------------------------------------------
138
+
139
+ export function createProxy ( opts : ProxyOptions = { } ) {
140
+ const uri =
141
+ opts . url ||
142
+ process . env . https_proxy ||
143
+ process . env . http_proxy ||
144
+ process . env . HTTPS_PROXY ||
145
+ process . env . HTTP_PROXY ;
146
+
147
+ if ( ! uri ) {
148
+ return {
149
+ agent : undefined ,
150
+ dispatcher : undefined ,
151
+ } ;
152
+ }
153
+
154
+ const _noProxy = opts . noProxy || process . env . no_proxy || process . env . NO_PROXY ;
155
+ const noProxy = typeof _noProxy === "string" ? _noProxy . split ( "," ) : _noProxy ;
156
+
157
+ const nodeAgent = new NodeProxyAgent ( { uri, noProxy } ) ;
158
+
159
+ // https://undici.nodejs.org/#/docs/api/ProxyAgent
160
+ const undiciAgent = new UndiciProxyAgent ( {
161
+ uri,
162
+ noProxy,
163
+ } ) ;
164
+
165
+ return {
166
+ agent : nodeAgent ,
167
+ dispatcher : undiciAgent ,
168
+ } ;
169
+ }
170
+
171
+ export function createFetch ( proxyOptions : ProxyOptions = { } ) {
172
+ const proxy = createProxy ( proxyOptions ) ;
173
+ return ( url , fetchOptions ) => _fetch ( url , { ...proxy , ...fetchOptions } ) ;
174
+ }
175
+
176
+ export const fetch = createFetch ( { } ) ;
0 commit comments