forked from xiangsx/gpt4free-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxyAgent.ts
25 lines (23 loc) · 963 Bytes
/
proxyAgent.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import axios, {AxiosInstance, CreateAxiosDefaults} from "axios";
import HttpsProxyAgent from "https-proxy-agent";
import {SessionConstructorOptions} from "tls-client/dist/esm/types";
import {Session} from "tls-client/dist/esm/sessions";
import tlsClient from "tls-client";
export function CreateAxiosProxy(config: CreateAxiosDefaults, proxy?: string): AxiosInstance {
const createConfig = {...config};
const useProxy = process.env.http_proxy || proxy;
if (useProxy) {
createConfig.proxy = false;
createConfig.httpAgent = HttpsProxyAgent(useProxy);
createConfig.httpsAgent = HttpsProxyAgent(useProxy);
}
return axios.create(createConfig);
}
export function CreateTlsProxy(config: SessionConstructorOptions, proxy?: string): Session {
const client = new tlsClient.Session(config);
const useProxy = process.env.http_proxy || proxy;
if (useProxy) {
client.proxy = useProxy;
}
return client;
}