* add https proxy * remove proxy in renderer * proxy work for openai request * use proxyAgent to enable system proxy * add proxy setting * tweak proxy setting
22 lines
564 B
TypeScript
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,
|
|
};
|
|
}
|