Files
everyone-can-use-english/enjoy/src/main/proxy-agent.ts
an-lee 51a810fdfd Feat: may setup proxy (#238)
* add https proxy

* remove proxy in renderer

* proxy work for openai request

* use proxyAgent to enable system proxy

* add proxy setting

* tweak proxy setting
2024-02-01 15:33:37 +08:00

22 lines
564 B
TypeScript

import settings from "@main/settings";
import { HttpsProxyAgent } from "https-proxy-agent";
import { ProxyAgent } from "proxy-agent";
import fetch from "node-fetch";
export default function () {
const proxyConfig = settings.getSync("proxy") as ProxyConfigType;
let proxyAgent = new ProxyAgent();
if (proxyConfig.enabled && proxyConfig.url) {
proxyAgent = new ProxyAgent({
httpAgent: new HttpsProxyAgent(proxyConfig.url),
httpsAgent: new HttpsProxyAgent(proxyConfig.url),
});
}
return {
httpAgent: proxyAgent,
fetch,
};
}