From c14b69346a67d4c426d7ddb32ef32812c449e67c Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 12 Oct 2025 22:25:29 +0100 Subject: feat: support passing multiple proxy values (#2039) * feat: support passing multiple proxy values * fix typo * trim and filter --- apps/workers/utils.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'apps/workers/utils.ts') diff --git a/apps/workers/utils.ts b/apps/workers/utils.ts index 55204570..a82dd12d 100644 --- a/apps/workers/utils.ts +++ b/apps/workers/utils.ts @@ -21,6 +21,10 @@ export function withTimeout( }; } +export function getRandomProxy(proxyList: string[]): string { + return proxyList[Math.floor(Math.random() * proxyList.length)].trim(); +} + function getProxyAgent(url: string) { const { proxy } = serverConfig; @@ -48,12 +52,14 @@ function getProxyAgent(url: string) { } if (protocol === "https:" && proxy.httpsProxy) { - return new HttpsProxyAgent(proxy.httpsProxy); + const selectedProxy = getRandomProxy(proxy.httpsProxy); + return new HttpsProxyAgent(selectedProxy); } else if (protocol === "http:" && proxy.httpProxy) { - return new HttpProxyAgent(proxy.httpProxy); + const selectedProxy = getRandomProxy(proxy.httpProxy); + return new HttpProxyAgent(selectedProxy); } else if (proxy.httpProxy) { - // Fallback to HTTP proxy for HTTPS if HTTPS proxy not configured - return new HttpProxyAgent(proxy.httpProxy); + const selectedProxy = getRandomProxy(proxy.httpProxy); + return new HttpProxyAgent(selectedProxy); } return undefined; -- cgit v1.2.3-70-g09d2