From a99e18c7447fb4faaea98dbbc7a484dc0912f1bb Mon Sep 17 00:00:00 2001 From: Vadym Samoilenko Date: Thu, 19 Mar 2026 22:32:49 +0000 Subject: [PATCH] Fix apiFetch basePath: use publicRuntimeConfig instead of NEXT_PUBLIC_ env var MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NEXT_PUBLIC_* vars are inlined at build time — not available in Docker build context. publicRuntimeConfig is resolved at runtime from next.config.mjs, which works correctly. Co-Authored-By: Claude Sonnet 4.6 --- frontend/lib/apiFetch.ts | 6 +++++- frontend/next.config.mjs | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/lib/apiFetch.ts b/frontend/lib/apiFetch.ts index c3de143..9b40ca8 100644 --- a/frontend/lib/apiFetch.ts +++ b/frontend/lib/apiFetch.ts @@ -2,9 +2,13 @@ * Wrapper around fetch that prepends the Next.js basePath so API calls * reach the correct backend when deployed under a sub-path (e.g. /ppt-tool). * + * basePath is read from next.config.mjs at build time via next/config. * Usage: apiFetch('/api/v1/...', options) — identical to fetch(), just works. */ -const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH ?? ''; +import getConfig from 'next/config'; + +const { publicRuntimeConfig } = getConfig() ?? {}; +const BASE_PATH: string = publicRuntimeConfig?.basePath ?? ''; export function apiFetch(path: string, init?: RequestInit): Promise { const url = path.startsWith('/api/') ? `${BASE_PATH}${path}` : path; diff --git a/frontend/next.config.mjs b/frontend/next.config.mjs index 43edf4b..a8eab82 100644 --- a/frontend/next.config.mjs +++ b/frontend/next.config.mjs @@ -4,6 +4,9 @@ const API_URL = process.env.API_INTERNAL_URL || 'http://localhost:8000'; const nextConfig = { basePath: "/ppt-tool", assetPrefix: "/ppt-tool", + publicRuntimeConfig: { + basePath: "/ppt-tool", + }, reactStrictMode: false, distDir: ".next-build",