REACT_APP_BACKEND_URL in Qovery, but in the browser your frontend reads:
https://frontend.example.com/backend.example.com/api).
Cause
The code of a React (Create React App), Vite or Next.js frontend that runs in the browser does not run in your container. Its build tool replacesprocess.env.REACT_APP_*, import.meta.env.VITE_* or process.env.NEXT_PUBLIC_* with fixed values when you run npm run build. After that, the files served to the browser no longer read any environment variable.
Qovery injects your variables into the running container, which is too late for these frameworks. A variable reaches the build only if the Dockerfile declares it. See Build-time variables.
Fix
1
Declare the variable as a build argument
In the build stage of your Dockerfile, add an In a multi-stage Dockerfile, declare the
ARG with the same name as the Qovery variable, before the build command:ARG in the stage that runs the build. An ARG declared in another stage is not visible there.2
Create the variable in Qovery
Create
REACT_APP_BACKEND_URL on the frontend service, or at environment level. To point at another service of the environment, create an alias on the built-in variable of the backend that ends in _HOST_EXTERNAL, named the way your frontend expects. The browser cannot reach the _HOST_INTERNAL host; see Use the public host name of the backend.3
Add the protocol
The built-in host variables hold a host name only, without
https://. Used as is, the browser treats the value as a relative path, which gives URLs like https://frontend.example.com/backend.example.com. Add the protocol where you build the URL:4
Redeploy the frontend
Changing the value of a variable declared as an
ARG changes the image tag, so Qovery builds the frontend again with the new value.Use the public host name of the backend
The browser calls your backend over the internet, so it needs the public host name of the backend, not its internal one. Use the variable ending in_HOST_EXTERNAL, which exists only when the backend has a publicly accessible port. A value ending in _HOST_INTERNAL only resolves inside the cluster. See Linking services together.
If the backend uses a custom domain, set the variable to that domain instead.