From 74e4c55277b6b9c8ccb6c87629c26eebd04c1be8 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 21 Feb 2026 22:45:57 -0800 Subject: [PATCH] fix: read API_BASE_URL at request time in proxy route The module-level const was being inlined at build time by Next.js standalone bundler, causing the proxy to always use localhost:8000 instead of the Docker runtime env var api-gateway:8000. Co-Authored-By: Claude Opus 4.6 --- it0-web-admin/src/app/api/proxy/[...path]/route.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/it0-web-admin/src/app/api/proxy/[...path]/route.ts b/it0-web-admin/src/app/api/proxy/[...path]/route.ts index a467e42..578ac68 100644 --- a/it0-web-admin/src/app/api/proxy/[...path]/route.ts +++ b/it0-web-admin/src/app/api/proxy/[...path]/route.ts @@ -1,6 +1,9 @@ import { NextRequest, NextResponse } from 'next/server'; -const API_BASE_URL = process.env.API_BASE_URL || 'http://localhost:8000'; +/** Read at request time so Docker runtime env vars are picked up (not inlined at build time). */ +function getApiBaseUrl(): string { + return process.env.API_BASE_URL || 'http://localhost:8000'; +} export async function GET(request: NextRequest, { params }: { params: { path: string[] } }) { return proxyRequest(request, params.path); @@ -19,7 +22,8 @@ export async function DELETE(request: NextRequest, { params }: { params: { path: } async function proxyRequest(request: NextRequest, path: string[]) { - const url = `${API_BASE_URL}/${path.join('/')}${request.nextUrl.search}`; + const apiBase = getApiBaseUrl(); + const url = `${apiBase}/${path.join('/')}${request.nextUrl.search}`; const headers: Record = {}; request.headers.forEach((value, key) => { @@ -43,6 +47,7 @@ async function proxyRequest(request: NextRequest, path: string[]) { headers: { 'Content-Type': response.headers.get('Content-Type') || 'application/json' }, }); } catch (error) { - return NextResponse.json({ error: 'Proxy error' }, { status: 502 }); + console.error(`Failed to proxy ${url}`, error); + return NextResponse.json({ error: 'Proxy error', detail: String(error) }, { status: 502 }); } }