Fix: remove duplicate /api prefix in local compose NEXT_PUBLIC_API_URL - #2
Open
mpont91 wants to merge 1 commit into
Open
Fix: remove duplicate /api prefix in local compose NEXT_PUBLIC_API_URL#2mpont91 wants to merge 1 commit into
mpont91 wants to merge 1 commit into
Conversation
The web dashboard failed to load any data when started with
docker-compose.local.yaml. Every request 404'd and the UI showed
"Failed to load leaderboard. Make sure the API server is running."
even though the API container was healthy.
The frontend already prepends /api to every route: fetchJson() in
src/lib/api.ts builds `${API_BASE}${path}` with paths such as
'/api/leaderboard'. Setting NEXT_PUBLIC_API_URL to
http://localhost:8000/api produced http://localhost:8000/api/api/...
which does not exist.
This affected the whole dashboard, not just the leaderboard:
/api/stats, /api/freshness, /api/index/psi-10, /api/activity/recent
and /api/ml/health all returned 404.
The other compose files already use the base URL without the prefix
(deploy/docker-compose.dev.yaml, deploy/docker-compose.prod.yaml), so
this aligns the local file with them.
deploy/.env.example intentionally keeps the /api suffix and is left
unchanged: in production nginx serves `location /api/` with
`proxy_pass http://api/`, whose trailing slash strips the prefix
before forwarding, so the suffix is required there to compensate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Starting the stack with
docker-compose.local.yamlas documented brings everycontainer up healthy, but the dashboard at
localhost:3000shows:The API is in fact running and healthy. Every browser request 404s:
Note the doubled
/api/api/.Cause
The frontend already prepends
/apito every route.fetchJson()inaware-fund/services/web/src/lib/api.ts:396builds:and callers pass paths that already carry the prefix, e.g.
fetchJson('/api/leaderboard')(line 442).docker-compose.local.yamlset the base URL with the prefix baked in:so the concatenation yields
http://localhost:8000/api/api/leaderboard.This is local-only: the browser talks straight to the API on port 8000 with no
reverse proxy in front to absorb the extra segment.
Fix
This matches what the other compose files already do:
deploy/docker-compose.dev.yaml:152→http://localhost:8000deploy/docker-compose.prod.yaml:209→${NEXT_PUBLIC_API_URL:-http://api:8000}Deliberately not changed
deploy/.env.example:57keepshttps://app.aware.fund/api. That suffix iscorrect for production:
deploy/nginx/nginx.conf:88servesand the trailing slash on
proxy_passstrips the/api/prefix beforeforwarding, so the doubled segment is exactly what makes the backend receive
/api/leaderboard. Removing the suffix there would break production.Verification
After the change, recreating only the
webcontainer:The served JS bundle now resolves the base to
localhost:8000with noduplicate segment, and the dashboard renders. A hard refresh is needed to drop
the previously cached bundle.