I have 3 different deployment environments for prod, test and dev.
On the frontend side the only thing that differentiates them is their config file, the code is identical.
So I thought that instead of creating 3 different build for each environment, it might make more sense to use the same build for every environment and just load the config file once before the react code is kicked off by the browser.
I know I can technically load external files as imports, but they are always loaded as promises which need to be fuffilled before they can be used, which introduces nasty state implications for react.
So is there a way to just load a config file from a url once and then just use it?
Asked
Active
Viewed 74 times
0

user2741831
- 2,120
- 2
- 22
- 43
-
What type of configuration file? environment.ENV_NAME.ts? Taking a configuration file from an URL after the deployment (I guess from the browser if I understood) will pubblicy expose your configuration file – Majico Oct 17 '22 at 14:43
-
Just a json config file. Ot could sit in public for example – user2741831 Oct 17 '22 at 15:20
-
I'm not really sure what do you mean with "just load the config file once before the react code is kicked off by the browser" but i whink this will be helpfull https://stackoverflow.com/questions/12460378/how-to-get-json-from-url-in-javascript or this https://stackoverflow.com/questions/2499567/how-to-make-a-json-call-to-an-url/2499647#2499647 (if you need pure js) to get the JSON config file from an url, just make sure to execute the script before the "main" (idk how is called) of the react app. – Majico Oct 17 '22 at 16:33
-
Basically, I would like the file to already be somehow in nodes import system before the react code starts running. So I don't have to fetch it, like you usually would – user2741831 Oct 17 '22 at 16:44