Skip to content

Commit c86ebdf

Browse files
fix(deploy): align containers with same-origin API proxy; make backend image runnable
- docker-compose: the frontend's Next server now proxies /api/v1/* to the backend, so point BACKEND_ORIGIN at the `backend` service (http://backend:8000), not localhost — otherwise the proxy hits the frontend container itself. Fixes `docker-compose up --build` after the proxy change. Drop the now-unused NEXT_PUBLIC_API_URL. - frontend/Dockerfile: build arg NEXT_PUBLIC_API_URL → BACKEND_ORIGIN (rewrites() is evaluated at build time). - backend/Dockerfile: add a default CMD honoring $PORT so the image starts on hosted platforms (Render/Railway/Fly/K8s); compose still overrides it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 905907d commit c86ebdf

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

‎backend/Dockerfile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ RUN pip install --no-cache-dir -r requirements.txt
1414
COPY . .
1515

1616
EXPOSE 8000
17+
18+
# Default production start. docker-compose overrides this with its own `command:`;
19+
# hosted platforms (Render/Railway/Fly/K8s) run it as-is and inject $PORT.
20+
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-8000}"]

‎docker-compose.yml‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ services:
4747
build:
4848
context: ./frontend
4949
args:
50-
NEXT_PUBLIC_API_URL: http://localhost:8000
50+
# The Next server proxies /api/v1/* to the backend (see next.config.ts).
51+
# Inside the compose network the backend is the `backend` service, not
52+
# localhost. rewrites() is evaluated at build time, so this must be a
53+
# build arg, and it's re-set at runtime below.
54+
BACKEND_ORIGIN: http://backend:8000
5155
container_name: stackradar_frontend
5256
ports:
5357
- "3000:3000"
5458
environment:
55-
- NEXT_PUBLIC_API_URL=http://localhost:8000
59+
- BACKEND_ORIGIN=http://backend:8000
5660
depends_on:
5761
- backend
5862
restart: unless-stopped

‎frontend/Dockerfile‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ WORKDIR /app
1010
COPY --from=deps /app/node_modules ./node_modules
1111
COPY . .
1212

13-
# Build-time env — override via docker-compose or --build-arg
14-
ARG NEXT_PUBLIC_API_URL=http://localhost:8000
15-
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
13+
# Backend origin for the /api/v1/* proxy rewrite. next.config.ts evaluates
14+
# rewrites() at build time, so this is a build arg. Override via docker-compose
15+
# or --build-arg (compose sets http://backend:8000; a hosted deploy sets its
16+
# public backend URL).
17+
ARG BACKEND_ORIGIN=http://localhost:8000
18+
ENV BACKEND_ORIGIN=$BACKEND_ORIGIN
1619

1720
# Enable Next.js standalone output for minimal Docker image
1821
ENV NEXT_TELEMETRY_DISABLED=1

0 commit comments

Comments
 (0)