I have Environment-specific variables stored in the spinnaker manifest. I want to replace some variables in the angular app when deployed to dev, qa, and prod environments. How to change my code to achieve this? I am doing this because I do not want to store those variables values in the source code as it is not safe.
I tried to find them my own but failed and I am desperate.
A common approach to managing environment variables in many projects is to use
.envfiles. Here is how you can do this for your Angular application:Creating
.envFiles:.envfile for each environment. For example:.env.dev,.env.qaand.env.prod.Integrating with Angular:
.envfile..envfile based on the target environment.Build Scripts:
package.json, define build scripts for each environment:Accessing Variables in Code:
environment.tsfiles to access these variables. For example:environmentfile and accessenvironment.apiUrl.Security:
.envfiles to your.gitignoreto ensure they are not pushed to the repository. This is crucial for keeping secrets and sensitive variables out of version control.Hope this helps you configure and manage your environment variables effectively for different environments in your Angular application!