From a3966e0c31fc924207606e24868ed8b602e28faa Mon Sep 17 00:00:00 2001 From: Tudor Date: Tue, 3 Feb 2026 10:46:03 +0000 Subject: [PATCH] Fix: Pass FASTAPI_URL as build arg for Next.js rewrites Next.js rewrites are evaluated at build time, not runtime. Without FASTAPI_URL set during build, the rewrite destination defaults to localhost:8000 which fails in Docker. - Add FASTAPI_URL build arg to nextjs-app/Dockerfile - Pass build arg in docker-compose.yml - Pass build arg in Gitea Actions workflow Co-Authored-By: Claude Opus 4.5 --- .gitea/workflows/build-and-push.yml | 2 ++ docker-compose.yml | 2 ++ nextjs-app/Dockerfile | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/.gitea/workflows/build-and-push.yml b/.gitea/workflows/build-and-push.yml index 242de7f..4f03f8f 100644 --- a/.gitea/workflows/build-and-push.yml +++ b/.gitea/workflows/build-and-push.yml @@ -89,6 +89,8 @@ jobs: push: ${{ gitea.event_name != 'pull_request' }} tags: ${{ steps.meta-frontend.outputs.tags }} labels: ${{ steps.meta-frontend.outputs.labels }} + build-args: | + FASTAPI_URL=http://backend:80/api # Cache disabled due to registry size limits # cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }}:buildcache # cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }}:buildcache,mode=max diff --git a/docker-compose.yml b/docker-compose.yml index f0217f0..9434c70 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -54,6 +54,8 @@ services: build: context: ./nextjs-app dockerfile: Dockerfile + args: + FASTAPI_URL: http://backend:80/api container_name: schoolcompare_nextjs ports: - "3000:3000" diff --git a/nextjs-app/Dockerfile b/nextjs-app/Dockerfile index 32ef1b4..42e0c6c 100644 --- a/nextjs-app/Dockerfile +++ b/nextjs-app/Dockerfile @@ -22,6 +22,10 @@ COPY . . ENV NEXT_TELEMETRY_DISABLED=1 ENV NODE_ENV=production +# Build argument for FastAPI URL (used by Next.js rewrites at build time) +ARG FASTAPI_URL=http://backend:80/api +ENV FASTAPI_URL=${FASTAPI_URL} + # Build application RUN npm run build