Skip to content

feat: runtime-configurable API URL via Next.js API route proxy#112

Merged
Trosper3 merged 1 commit into
ReduxISU:ReduxAPI_GUIfrom
wrigjl:feat/issue-99-nextjs-rewrite-proxy
Jun 19, 2026
Merged

feat: runtime-configurable API URL via Next.js API route proxy#112
Trosper3 merged 1 commit into
ReduxISU:ReduxAPI_GUIfrom
wrigjl:feat/issue-99-nextjs-rewrite-proxy

Conversation

@wrigjl

@wrigjl wrigjl commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Closes #99

Summary

  • Replaces NEXT_PUBLIC_REDUX_BASE_URL (baked into the JS bundle at build time) with a server-side REDUX_BASE_URL read at request time by a Next.js API route proxy at /api/redux/[...path]
  • The frontend hardcodes /api/redux/ as its base URL; the proxy forwards all requests to the real API, preserving method, headers, query string, and body
  • Returns clear JSON errors on misconfiguration (REDUX_BASE_URL not set → HTTP 500) or upstream failure (unreachable → HTTP 502)
  • One Docker image works for every environment — set the API URL at docker run time:
    docker run -e REDUX_BASE_URL=https://api.redux.portneuf.cose.isu.edu/ ...
    

Key files

File Change
pages/api/redux/[...path].js New proxy route
pages/index.js Base URL → /api/redux/
.env.development Renamed var to REDUX_BASE_URL (value unchanged)
.env.production Removed REDUX_BASE_URL (no default baked into image)
next.config.js Reverted — rewrites are evaluated at build time, not runtime
Dockerfile Removed stale NEXT_PUBLIC_REDUX_BASE_URL build arg

Test plan

  • Built Docker image without REDUX_BASE_URL set; hitting /api/redux/* returns {"error":"REDUX_BASE_URL is not configured"}
  • Ran container with -e REDUX_BASE_URL=http://redux.thought.net:27000/; real API responded correctly through the proxy
  • npm run dev still uses localhost:27000 via .env.development

Note on rewrites

The issue proposed using next.config.js rewrites. Investigation showed that the rewrite destination is resolved at next build time and compiled into server.js — runtime env vars have no effect. An API route is the correct approach for true runtime configurability.

🤖 Generated with Claude Code

Replaces the build-time NEXT_PUBLIC_REDUX_BASE_URL with a server-side
REDUX_BASE_URL read at request time via a Next.js API route proxy at
/api/redux/[...path]. This allows a single Docker image to target any
deployment environment by passing -e REDUX_BASE_URL=... at docker run
time — no rebuild required.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

@Trosper3 Trosper3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprising to me still that the old environment variable was baked at build time. I think this will help make our Docker images more flexible.

@Trosper3 Trosper3 merged commit 32c93fb into ReduxISU:ReduxAPI_GUI Jun 19, 2026
7 checks passed
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.

feat: use Next.js rewrite proxy to make API URL runtime-configurable

2 participants