From c4a8d84c49f7ab2830a6e716bce2b0432c502b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Harnes?= Date: Thu, 22 Jan 2026 10:20:09 +0100 Subject: [PATCH] feat: add HTTP/HTTPS proxy support --- package.json | 1 + pnpm-lock.yaml | 9 +++++++++ src/instrumentation.ts | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/package.json b/package.json index 1a73a3fd8..ae908468c 100644 --- a/package.json +++ b/package.json @@ -127,6 +127,7 @@ "ts-edge": "^1.0.4", "ts-safe": "^0.0.5", "tw-animate-css": "^1.4.0", + "undici": "^7.18.2", "vaul": "^1.1.2", "zod": "^4.2.1", "zustand": "^5.0.9" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a7dfec357..d304e0d50 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -245,6 +245,9 @@ importers: tw-animate-css: specifier: ^1.4.0 version: 1.4.0 + undici: + specifier: ^7.18.2 + version: 7.18.2 vaul: specifier: ^1.1.2 version: 1.1.2(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(react-dom@19.2.3(react@19.2.3))(react@19.2.3) @@ -6285,6 +6288,10 @@ packages: resolution: {integrity: sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg==} engines: {node: '>=14.0'} + undici@7.18.2: + resolution: {integrity: sha512-y+8YjDFzWdQlSE9N5nzKMT3g4a5UBX1HKowfdXh0uvAnTaqqwqB92Jt4UXBAeKekDs5IaDKyJFR4X1gYVCgXcw==} + engines: {node: '>=20.18.1'} + unified@11.0.5: resolution: {integrity: sha512-xKvGhPWw3k84Qjh8bI3ZeJjqnyadK+GEFtazSfZv/rKeTkTjOJho6mFqh2SM96iIcZokxiOpg78GazTSg8+KHA==} @@ -13405,6 +13412,8 @@ snapshots: dependencies: '@fastify/busboy': 2.1.1 + undici@7.18.2: {} + unified@11.0.5: dependencies: '@types/unist': 3.0.3 diff --git a/src/instrumentation.ts b/src/instrumentation.ts index 7c999f307..3ed1e7f07 100644 --- a/src/instrumentation.ts +++ b/src/instrumentation.ts @@ -2,6 +2,17 @@ import { IS_VERCEL_ENV } from "lib/const"; export async function register() { if (process.env.NEXT_RUNTIME === "nodejs") { + // Enable proxy support for undici (used by AI SDK) via HTTP_PROXY/HTTPS_PROXY env vars + const proxyUrl = + process.env.HTTPS_PROXY || + process.env.https_proxy || + process.env.HTTP_PROXY || + process.env.http_proxy; + if (proxyUrl) { + const { ProxyAgent, setGlobalDispatcher } = await import("undici"); + console.log(`[proxy] Using proxy for fetch requests: ${proxyUrl}`); + setGlobalDispatcher(new ProxyAgent(proxyUrl)); + } if (!IS_VERCEL_ENV) { // run DB migration const runMigrate = await import("./lib/db/pg/migrate.pg").then(