feat(infra): move backend url from build time to runtime #54
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Currently, the backend is baked in on build time (either manual build or docker build).
This makes especially the docker image less valuable, as it is not portable from one to the other backend. It even makes it strenuous in the situation of testing etc, as each has to have their own docker image.
It would be great if we could find a way to make it work in runtime, such that it is portable. It would even be sufficient if we could simply know it is always on the
/apipath for the origin of the frontend (for example,https://researchequals.com->/apiandhttps://test.researchequals.com->/api)It seems like we are already handling the API redirection in the reverse proxy level 😅
and we can do the same in the vite config for local development:
By replacing the backend urls to be relative (eg
/api/files/<key>) it would immediately land in the right place because the reverse proxy manages it lands in the correct place. Vite already acts as reverse proxy in the local development space. Only the server side would need to still have the api variable, which can then be run in the process environment.okay great – the client side components are now using relative paths, which gets captured by the reverse proxy (also covered in the vite setup for local development).
server side rendering is NOT yet covered and is a breaking change, so will have to be reserved for the next major release. There are some quirks that I figured out and I am able to confirm it can work in practice ✅ Please note the following
Core change
import.meta.env.PUBLIC_API_BASEbecomesprocess.env.PUBLIC_API_BASELocal development
In order to properly test this:
host.docker.internalinstead oflocalhost, given thatlocalhostwould refer to within the Docker container, which is incorrect.host.docker.internalis the machine itself.Deployment