Skip to content

security: proxy /api and /healthz to backend via Next.js rewrites#327

Open
davenicoll wants to merge 1 commit into
abhi1693:masterfrom
davenicoll:feat/frontend-api-proxy
Open

security: proxy /api and /healthz to backend via Next.js rewrites#327
davenicoll wants to merge 1 commit into
abhi1693:masterfrom
davenicoll:feat/frontend-api-proxy

Conversation

@davenicoll
Copy link
Copy Markdown

Summary

Adds Next.js rewrites so the frontend proxies /api/* and /healthz requests to the backend over the internal Docker network.

Why

When the frontend is the only service exposed externally (e.g. behind a Cloudflare Tunnel or a single reverse proxy on port 3000), browser requests to /api/* have no route to the backend. The current options are to expose the backend port publicly or set up a second ingress, both of which leak internal services onto the network unnecessarily.

With these rewrites the frontend forwards API traffic to http://backend:8000 inside the compose network, so the backend never needs to be reachable from outside.

Changes

  • frontend/next.config.ts: added rewrites() mapping /api/:path* and /healthz to the backend service.

Test plan

  • docker compose up --build with NEXT_PUBLIC_API_URL set to the frontend origin
  • Verify /api/v1/users/me returns JSON, not the frontend HTML
  • Verify /healthz proxies correctly
  • Confirm no change in behaviour when accessing the backend directly on its own port

When deployed behind a single ingress (e.g. Cloudflare Tunnel) pointing
only at the frontend, browser requests to /api/* have no route to the
backend.  Adding Next.js rewrites lets the frontend forward these
requests to the backend over the internal Docker network, so the API
never needs to be exposed externally.
@davenicoll davenicoll changed the title Proxy /api and /healthz to backend via Next.js rewrites security: proxy /api and /healthz to backend via Next.js rewrites Apr 7, 2026
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.

1 participant