fix(docker): SPA must use same-origin API base in the server image (CORS)
apps/web/.env.production sets VITE_API_BASE=http://127.0.0.1:3000 for the TAURI desktop build (which loads from tauri://localhost and needs an absolute backend origin). But Vite auto-loads .env.production for ANY `vite build`, so the server image baked 127.0.0.1:3000 into the browser bundle — loading the UI from a real host (e.g. http://parksystems.msai.al) then made the browser call 127.0.0.1:3000 cross-origin and fail the Same-Origin Policy on /api/auth/login. Fix: the server Dockerfile writes apps/web/.env.production.local with an empty VITE_API_BASE before the web build (.local has higher Vite precedence), so the SPA served by Fastify stays relative/same-origin (/api/...). The desktop build is unaffected (it doesn't use this Dockerfile). Verified: 127.0.0.1:3000 no longer in the built bundle; /api/auth/login is relative. Claude-Session: https://claude.ai/code/session_01Xcm6ikLgGoCxxHrxtjkk5V
This commit is contained in:
@@ -27,6 +27,12 @@ ENV CI=true
|
||||
COPY . .
|
||||
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \
|
||||
pnpm install --frozen-lockfile --offline
|
||||
# Force the SPA to use a SAME-ORIGIN (relative) API base for THIS image. Vite auto-loads
|
||||
# apps/web/.env.production, which sets VITE_API_BASE=http://127.0.0.1:3000 for the TAURI
|
||||
# DESKTOP build — but here Fastify serves the SPA same-origin, so an absolute base would
|
||||
# make the browser hit 127.0.0.1:3000 cross-origin and fail CORS. `.env.production.local`
|
||||
# has higher precedence than `.env.production`, so this empties it for the server image only.
|
||||
RUN echo 'VITE_API_BASE=' > apps/web/.env.production.local
|
||||
# Builds shared/db/devices, the server dist, AND the web SPA dist (apps/web/dist).
|
||||
RUN pnpm turbo run build --filter=@parking/server --filter=@parking/web
|
||||
# `pnpm deploy` produces a SELF-CONTAINED prod bundle for the server in /deploy: a hoisted
|
||||
|
||||
Reference in New Issue
Block a user