evolution-api/src/utils/makeProxyAgent.ts
Judson Junior 5292e569d9 Remove unused dependencies and refactor proxy handling
In some tests made on the testProxy function, the `new ProxyAgent()` was not working, even adding it the IP result was the same.

I've change it to the `new HttpsProxyAgent()` and it worked.

Refactored the proxy agent to center the same function/creation the same where it is used
2024-01-21 13:54:42 -03:00

18 lines
503 B
TypeScript

import { HttpsProxyAgent } from 'https-proxy-agent';
import { wa } from '../whatsapp/types/wa.types';
export function makeProxyAgent(proxy: wa.Proxy | string) {
if (typeof proxy === 'string') {
return new HttpsProxyAgent(proxy);
}
const { host, password, port, protocol, username } = proxy;
let proxyUrl = `${protocol}://${host}:${port}`;
if (username && password) {
proxyUrl = `${protocol}://${username}:${password}@${host}:${port}`;
}
return new HttpsProxyAgent(proxyUrl);
}