T
T
Tim_Grr2019-09-12 23:11:40
React
Tim_Grr, 2019-09-12 23:11:40

Is it possible to dynamically read environment variables from the .env file from the create-react-app production build?

I need to dynamically assign a port for internal requests to the server in my production build, since I cannot know in advance exactly which port my application will run on, is it possible to dynamically read the value from the outside and use it on the fly in my production build?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2019-09-12
@miraage

I need to dynamically assign a port for internal requests to the server in my production build, since I cannot know in advance exactly which port my application will run on, is it possible to dynamically read the value from the outside and use it on the fly in my production build?

I have a similar situation, it is necessary to consider url, client_id, etc., which are unknown at the build stage.
Throw some env.json with the necessary parameters into the public folder, and then read it through fetch / xhr.
Fumble through Context API / thunk.withExtraArgument / saga extra args / ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question