docker – Configure JS application using environment variables and Nginx

There is React app that is built in pipeline using Vite and pushes to container registry then pulls by Portainer when stack updates.

It is necessary to make possible configure env variables from Portainer interface to edit it in bundle which sends to client.

I came up with poor solution to make it with sub_filter module in Nginx which replaces strings in files which sends to client. But in this case the configuration file of Nginx increases to very big sizes because for one env variable it has to write 2 – 3 lines of sub_filter config. Also it’s risky because programmer can forgot about one variable and won’t configure it.

Is there a more concise way to achieve this without changing the set of tools (Vite, Nginx, Portainer), since I know that this is relatively easy to do through Kubernetes?

Read more here: Source link