infisical icon indicating copy to clipboard operation
infisical copied to clipboard

Allow configuring `API_URL` for frontend

Open IgnisDa opened this issue 2 years ago • 6 comments

Thanks for the wonderful project!

Feature description

Right now the frontend makes always makes backend requests to the same domain. This should be made configurable via an API_URL env var.

Why would it be useful?

I have the backend hosted on a different domain than the one frontend is in. Thus, when the frontend makes requests to https://infisical.<domain>/api/v1/auth/login1, the request fails. I have the backend live on https://infisical-backend.<domain>.

Solution

Perhaps it can be configured on the frontend image via an API_URL env var which defaults to the current domain to preserve backwards compatibility.

Additional context

I am using dokku to self host infisical.

IgnisDa avatar Jan 22 '23 16:01 IgnisDa

On a cursory look through the code, this should be possible by modifying https://github.dev/Infisical/infisical/blob/4db4c172c14c8370bd6cf1ee8e685219e8f81d92/frontend/src/components/utilities/SecurityClient.ts#L10.

I can work on a PR if approved.

IgnisDa avatar Jan 22 '23 16:01 IgnisDa

@mv-turtle has more context for the frontend, he will get back to this soon! Thanks for the suggestion

maidul98 avatar Jan 22 '23 21:01 maidul98

Let's try doing that! I remember we had some problems with env vars on the front end. I think @dangtony98 or @reginaldbondoc would have more input

vmatsiiako avatar Jan 22 '23 23:01 vmatsiiako

@mv-turtle Making a PR for this.

IgnisDa avatar Jan 23 '23 02:01 IgnisDa

Hey @IgnisDa!

Yeah feel free to add it but you should test that it works in the full build for the frontend (not just in development) and adjust for that.

What we found with Next.js is that environment variables get passed in at buildtime (not runtime); this limitation meant potentially hardcoding environment variables into Docker images but this wouldn't work for folks self-hosting. So we had to implement substitution at runtime.

dangtony98 avatar Jan 23 '23 03:01 dangtony98

@dangtony98 How could I go about testing it in prod? The docker-compose.yml file uses images from docker hub.

IgnisDa avatar Jan 23 '23 03:01 IgnisDa