Skip to content

fix(frontend): bake relative NEXT_PUBLIC_API_URL=/api (fixes #70)#74

Open
jcschaff wants to merge 1 commit into
mainfrom
fix/70-frontend-relative-api-url
Open

fix(frontend): bake relative NEXT_PUBLIC_API_URL=/api (fixes #70)#74
jcschaff wants to merge 1 commit into
mainfrom
fix/70-frontend-relative-api-url

Conversation

@jcschaff

Copy link
Copy Markdown
Member

Fixes #70.

Problem

The frontend image hardcoded NEXT_PUBLIC_API_URL=http://k8s-wn-01.cam.uchc.edu:30001 at build time (it's inlined into the browser bundle), so the browser's data/chat calls never hit the environment's own ingress — they went to that fixed NodePort regardless of where the app was deployed.

Fix

The ingress serves the frontend at / and the backend at /api on the same host, so bake a relative /api. The browser then calls the same origin it's served from, the ingress routes /api → backend (stripping /api), and one image works in every environment (dev/prod/local) — no per-env images, no runtime injection.

  • frontend/Dockerfile: ARG/ENV NEXT_PUBLIC_API_URL defaulting to /api; dropped the COPY .env step (overridable with --build-arg NEXT_PUBLIC_API_URL=<absolute-url> if the frontend is ever served on a different origin than the API).
  • .github/workflows/build_containers.yml: pass --build-arg NEXT_PUBLIC_API_URL=/api instead of writing a hardcoded NodePort .env.

Safe because all usages are client-side

Every NEXT_PUBLIC_API_URL reference is a browser fetch (client components); there is no SSR/server-action use, so a relative URL always resolves against the correct origin in the browser.

Validation

Tag 0.1.8 builds both images with the fix; the deployment PR (#73) points its overlays at 0.1.8 and it's verified live on the dev cluster.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XpNzobVi83p3YKL9sqtGwZ

The frontend image hardcoded NEXT_PUBLIC_API_URL=http://k8s-wn-01...:30001 at
build time, so the browser's data/chat calls never hit the environment's own
ingress. Since the ingress serves the frontend at / and the backend at /api on
the same host, bake a RELATIVE "/api" instead: the browser calls the same origin
it's served from, the ingress routes /api -> backend, and one image works in
every environment.

- frontend/Dockerfile: ARG/ENV NEXT_PUBLIC_API_URL defaulting to /api; drop the
  COPY .env step
- build_containers.yml: pass --build-arg NEXT_PUBLIC_API_URL=/api instead of
  writing a hardcoded NodePort .env

Fixes #70.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XpNzobVi83p3YKL9sqtGwZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Frontend NEXT_PUBLIC_API_URL is baked into the image at build time (not environment-portable)

1 participant