From b7930014abbeb4445b15a12c060a9fc396561bd4 Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Sat, 29 Nov 2025 12:31:31 +0000 Subject: [PATCH] fix: use axios proxy config properly --- src/utils/Fetcher.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/utils/Fetcher.ts b/src/utils/Fetcher.ts index 0481b59..ac0f731 100644 --- a/src/utils/Fetcher.ts +++ b/src/utils/Fetcher.ts @@ -37,6 +37,8 @@ interface FlareSolverrResult { version: string; } +type ProxyConfig = Pick; + export type CustomRequestConfig = AxiosRequestConfig & { minCacheTtl?: number; queueLimit?: number; @@ -56,8 +58,7 @@ export class Fetcher { private readonly axios: AxiosInstance; private readonly logger: winston.Logger; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - private readonly proxyAgents = new Map>(); + private readonly proxyConfig = new Map(); private readonly rateLimitedCache = new Cacheable({ primary: new Keyv({ store: new CacheableMemory({ lruSize: 1024 }) }) }); private readonly semaphores = new Map(); private readonly hostUserAgentMap = new Map(); @@ -166,9 +167,9 @@ export class Fetcher { 'X-Forwarded-Proto': forwardedProto, 'X-Real-IP': ctx.ip, }), - ...(proxyUrl && this.getProxyAgents(proxyUrl)), ...requestConfig?.headers, }, + ...(proxyUrl && this.getProxyConfig(proxyUrl)), url: finalUrl.href, timeout: this.DEFAULT_TIMEOUT, transformResponse: [data => data], @@ -344,19 +345,19 @@ export class Fetcher { return undefined; } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - private getProxyAgents(proxyUrl: URL): Record<'httpAgent' | 'httpsAgent', any> { - let proxyAgents = this.proxyAgents.get(proxyUrl.href); + private getProxyConfig(proxyUrl: URL): ProxyConfig { + let proxyConfig = this.proxyConfig.get(proxyUrl.href); - if (!proxyAgents) { - proxyAgents = { + if (!proxyConfig) { + proxyConfig = { httpAgent: proxyUrl.protocol === 'socks5:' ? new SocksProxyAgent(proxyUrl) : new HttpProxyAgent(proxyUrl), httpsAgent: proxyUrl.protocol === 'socks5:' ? new SocksProxyAgent(proxyUrl) : new HttpsProxyAgent(proxyUrl), + proxy: false, }; - this.proxyAgents.set(proxyUrl.href, proxyAgents); + this.proxyConfig.set(proxyUrl.href, proxyConfig); } - return proxyAgents; + return proxyConfig; } }