Skip to content

fix: reach the backend through SERVER_BASE_URL in the projects route - #632

Open
lbarrosby wants to merge 1 commit into
AsyncFuncAI:mainfrom
lbarrosby:fix-projects-route-server-base-url
Open

lbarrosby wants to merge 1 commit into
AsyncFuncAI:mainfrom
lbarrosby:fix-projects-route-server-base-url

Conversation

@lbarrosby

Copy link
Copy Markdown
Contributor

src/app/api/wiki/projects/route.ts builds its backend URL from PYTHON_BACKEND_HOST. Nothing sets that variable and no README mentions it. Every other API route (/api/wiki/tasks, /api/chat/stream, /api/models/config, ...) and the rewrites in next.config.ts use SERVER_BASE_URL, which docker-compose.yml and the Dockerfile set to http://localhost:${PORT}.

So when the API is not on localhost:8001, for example with PORT=8002 in .env (the README tells you to keep SERVER_BASE_URL in sync with it) or with the API on another host, the rest of the app works but the project list on the home page and "delete project" go to localhost:8001 and fail with 503 Failed to connect to the Python backend.

The route now uses SERVER_BASE_URL first. PYTHON_BACKEND_HOST is kept as a fallback, so anyone who did set it is not affected.

Check: I ran GET from the route with Node (next/server stubbed with a module hook) against a stub backend on 127.0.0.1:8002 and SERVER_BASE_URL=http://127.0.0.1:8002:

# main
{"body":{"error":"Failed to connect to the Python backend. fetch failed"},"status":503}
# this branch
{"body":[{"id":"x","path":"/api/processed_projects"}],"status":200}

DELETE uses the same base URL (CACHE_API_ENDPOINT), so it is fixed as well.

/api/wiki/projects read PYTHON_BACKEND_HOST, which nothing sets or
documents, while every other route and the rewrites use SERVER_BASE_URL.
With the API on another host or with PORT changed in docker-compose,
the home page project list and project deletion failed with 503 while
the rest of the app worked. Prefer SERVER_BASE_URL and keep
PYTHON_BACKEND_HOST as a fallback.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
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