[AGE-3189] [Bug] Malformed Frontend API Requests with Double Prefix /api/api/ Causing Routing Issues
Describe the bug
Some requests sent from the frontend to the APIs are malformed and are not correctly routed to the API server. Specifically, certain API requests contain a double prefix /api/api/ instead of the expected /api/ in the path.
Observations: This issue does not appear to affect the cloud instance or the self-hosted version managed by Traefik for reasons I currently don't undestand. However, it causes failures when routing through other systems such as NGINX or AWS ALB.
To Reproduce go to homepage, in the browser look at API calls done by the frontend.
Expected behavior
All api calls done on /api/.
Screenshots
Example on the Cloud instance
SelfHosted with traffic
SelfHosted with custom reverse-proxy
The double /api/api/ prefix in frontend API requests is caused by how the base API URL is set via the NEXT_PUBLIC_AGENTA_API_URL environment variable. The frontend code constructs API requests by concatenating this base URL with endpoint paths like /apps or /containers/templates. If the base URL already includes /api and the endpoint also starts with /api, you end up with /api/api/ in the final request path. There’s no logic in the code to prevent this duplication, so it’s important to set the environment variable correctly at build time—ideally, the base URL should not include /api if the endpoints already do, or vice versa. This is especially relevant for Docker deployments, where you must use build arguments and rebuild the frontend image for changes to take effect (source).
Traefik often rewrites paths or is configured to handle /api prefixes more flexibly, which can mask this issue. In contrast, NGINX and AWS ALB typically route requests strictly based on the path, so a double prefix will cause routing failures and 404 errors (source). There’s no proxy-specific detection in the frontend; it’s all about how the base URL is configured.
To avoid this issue, double-check your NEXT_PUBLIC_AGENTA_API_URL value and ensure it matches your proxy and backend setup. If you’re using a reverse proxy that expects /api at the root, set the base URL without /api; if not, include it as needed. Always rebuild the frontend after changing this variable.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
Hello @vjeantet
Thanks for opening this issue. I was able to reproduce the issue. Indeed we are calling the wrong URL with api/api.
I think the reason it ends up working is because the way traefik is configured (it strips that api/ from the request).
In any case, we'll be fixing this shortly to use the right URL.