From fee42e1e5af320e6e67819a460238f0be6a5a2b8 Mon Sep 17 00:00:00 2001 From: Rqirus <32359512+Rqirus@users.noreply.github.com> Date: Thu, 26 Feb 2026 18:50:40 +0800 Subject: [PATCH] respect HTTP_PROXY env --- apps/api/src/main.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index a8de3dc5e..c1292ed6f 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -16,11 +16,23 @@ import { NestFactory } from '@nestjs/core'; import type { NestExpressApplication } from '@nestjs/platform-express'; import { NextFunction, Request, Response } from 'express'; import helmet from 'helmet'; +import { ProxyAgent, setGlobalDispatcher } from 'undici'; import { AppModule } from './app/app.module'; import { environment } from './environments/environment'; async function bootstrap() { + // Configure HTTP/HTTPS proxy for fetch() - Node.js fetch does NOT automatically + // use HTTP_PROXY/HTTPS_PROXY env vars (unless Node 22.21+ with NODE_USE_ENV_PROXY=1) + const proxyUrl = + process.env.HTTPS_PROXY || + process.env.https_proxy || + process.env.HTTP_PROXY || + process.env.http_proxy; + if (proxyUrl) { + setGlobalDispatcher(new ProxyAgent(proxyUrl)); + Logger.log(`Using proxy: ${proxyUrl.replace(/:[^:@]+@/, ':****@')}`); + } const configApp = await NestFactory.create(AppModule); const configService = configApp.get(ConfigService); let customLogLevels: LogLevel[];