import { ConfigService } from "@nestjs/config"; import { HttpModuleOptions } from "@nestjs/axios"; import { SocksProxyAgent } from "socks-proxy-agent"; /** * Shared HttpModule.registerAsync factory that applies the SOCKS proxy * when SOCKS_PROXY_HOST + SOCKS_PROXY_PORT env vars are set. * Used by every module that imports HttpModule. */ export function createHttpModuleOptions( configService: ConfigService, ): HttpModuleOptions | Promise { const socksHost = configService.get("SOCKS_PROXY_HOST"); const socksPort = configService.get("SOCKS_PROXY_PORT"); if (socksHost && socksPort) { const proxyUrl = `socks5://${socksHost}:${socksPort}`; const agent = new SocksProxyAgent(proxyUrl); return { httpsAgent: agent, httpAgent: agent, proxy: false, }; } return {}; }