From 2d1f8e4156cd5f8f6e4ff69a8bcb332fa529a62b Mon Sep 17 00:00:00 2001 From: Suriyakumarvijayanayagam Date: Fri, 14 Aug 2026 13:00:37 +0530 Subject: [PATCH] Remove the empty VITE_API_BASE_URL build arg - it overrode .env.production The deployed bundle shipped with no API base URL, so every request fell back to a relative /api/*, which the frontend's nginx forwards to a backend:8000 service this deployment does not have. The cause was this Dockerfile. Vite gives a real environment variable precedence over its .env files, so `ARG VITE_API_BASE_URL=""` followed by `ENV VITE_API_BASE_URL=$VITE_API_BASE_URL` did not leave the value unset - it set it to an empty string and overrode .env.production. Nothing about the build says so; it just quietly produces a bundle with no API host. Reproduced directly: building with VITE_API_BASE_URL="" in the environment yields a bundle with no API URL, and building with the variable unset bakes in https://mcp.nearle.ai.in from .env.production. The value now comes from .env.production alone. Point a build elsewhere by editing that file or adding .env.local; both are read by Vite and neither can be silently empty. Co-Authored-By: Claude Opus 5 (1M context) --- Dockerfile | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0e7b3c2..b3e9858 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,21 +7,18 @@ RUN npm ci COPY . . -# Which origin the built app sends its API calls to. +# Which origin the built app calls comes from .env.production, committed next to +# this file, and Vite inlines it at build time. # -# Vite inlines env vars at build time, so this MUST be a build arg - setting it -# on the running container has no effect, the value is already baked into the -# JS bundle. +# There is deliberately no ARG/ENV VITE_API_BASE_URL here. Vite gives a real +# environment variable precedence over its .env files, so declaring one with an +# empty default did not "leave it unset" - it actively set the value to an empty +# string and overrode .env.production. The build succeeded, the bundle shipped +# with no API base URL, and every request fell back to a relative /api/* that +# nginx forwards to a backend service this deployment does not have. # -# docker build --build-arg VITE_API_BASE_URL=https://mcp.nearle.ai.in . -# -# Left empty by default, which keeps requests relative and same-origin so the -# nginx /api/* proxy below serves them. Set it when the API is on its own -# domain - and add this app's origin to the backend's API_CORS_ORIGINS, or the -# browser will block the responses. -ARG VITE_API_BASE_URL="" -ENV VITE_API_BASE_URL=$VITE_API_BASE_URL - +# To point a build somewhere else, edit .env.production, or add .env.local +# (ignored by git) - both are read by Vite and neither is silently empty. RUN npm run build # ---- Serve stage ----