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
This commit is contained in:
21
enjoy/src/main/proxy-agent.ts
Normal file
21
enjoy/src/main/proxy-agent.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user