Add built-in proxy settings for Electron and Gateway (#239)
Co-authored-by: zuolingxuan <zuolingxuan@bytedance.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
c09b45832b
commit
e40f4b2163
21
electron/utils/proxy-fetch.ts
Normal file
21
electron/utils/proxy-fetch.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Use Electron's network stack when available so requests honor
|
||||
* session.defaultSession.setProxy(...). Fall back to the Node global fetch
|
||||
* for non-Electron test environments.
|
||||
*/
|
||||
|
||||
export async function proxyAwareFetch(
|
||||
input: string | URL,
|
||||
init?: RequestInit
|
||||
): Promise<Response> {
|
||||
if (process.versions.electron) {
|
||||
try {
|
||||
const { net } = await import('electron');
|
||||
return await net.fetch(input, init);
|
||||
} catch {
|
||||
// Fall through to the global fetch.
|
||||
}
|
||||
}
|
||||
|
||||
return await fetch(input, init);
|
||||
}
|
||||
Reference in New Issue
Block a user