I have a React app deployed to Azure. Now in my code i want to use the settings from the Configuration section in my react app in Azure. At the moment i am putting values in the "launchsettings.json" file and reading them in my react app as follows:
Environment.GetEnvironmentVariable(<the name of the section>)
I have noticed that the launchsettings.json file is not deployed. So do i need to add those values in the Configuration section of the Azure app .I alos connect to an azure db via a direct connection string in the code , i want to put it in a config file of some sort .
Also when i want to read them in the app is it
Environment.GetEnvironmentVariable or ConfigurationManager.AppSettings.GetValues()
Which do i use in my app and why isnt the launchsettings.json file being deployed from Visual Studio ?
I tried to copy the launchsettings file manually , but that didnt work .. cani deploy it with the app ?
2
Answers
The launchsettings.json file is only used for local development and is not deployed to Azure App Service. You need to store your configuration settings in the Configuration section of your Azure app. This is the recommended way to manage configuration settings for your app in production.
Yes, you should store your database connection string in the Configuration section of your Azure app as well. This will help to protect your connection string from being exposed in your code. You can then use the process.env.DB_CONNECTION_STRING environment variable to access the connection string in your code.
Here are the steps on how to store your settings in the Configuration section of your Azure app:
Once you have stored your settings in the Configuration section, you can access them in your code using the process.env
You cannot pull connection strings or app settings from the hosting server in a react app because you have no backend code.
You need a backend API or some other form of server side code to do what you’re trying to do.