E
E
Eugene2019-09-23 15:43:30
React
Eugene, 2019-09-23 15:43:30

How to pass env variable to compiled React application?

There is a docker container with a react application, it should be one (without compiling for each case). You need to run several copies of the container, pass the API server URL to them through an environment variable, and so that the application downloaded from a specific container works with its API server.
There was an idea to make a settings.js file with settings (the file is generated via bash when the container is started) and add it to index.html, but for some reason in React I can’t access the variable declared in it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
grinat, 2019-09-23
@eugeneledenev

In skomplinnnoe in any way, it is possible to transfer only at a stage of compilation of transpilation. Just edit the sources, in settings.js which forms the entrypoint (you probably don’t see it because the visibility is not the same, it’s easier to attach it to windows in this case), you can still change it in the sources via sed, you can edit index.html and insert there as a meta attribute.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question