-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
181 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// proxyFetch.ts | ||
let proxyFetch: typeof fetch | undefined; | ||
|
||
export async function initProxyFetch() { | ||
const proxyUrl = | ||
process.env.HTTP_PROXY || | ||
process.env.HTTPS_PROXY || | ||
process.env.http_proxy || | ||
process.env.https_proxy; | ||
|
||
if (proxyUrl && typeof window === "undefined") { | ||
const { ProxyAgent, fetch: undici } = await import("undici"); | ||
const dispatcher = new ProxyAgent(proxyUrl); | ||
return (...args: Parameters<typeof fetch>): ReturnType<typeof fetch> => { | ||
// @ts-expect-error `undici` has a `duplex` option | ||
return undici(args[0], { ...args[1], dispatcher }); | ||
}; | ||
} | ||
return undefined; | ||
} |