Angular 6 / Nginx / Docker / Kubernetes: configure environment variables for different environments
It is usually good to have an endpoint on server which gets called during app initialisation, this way you won't hard code anything on client side which can be viewed by end user.
However, just having that won't be enough as you need to somehow protect them if stored on cache or local storage.
Ultimately, if you are exposing the value of any "environment variable" to your angular application it is therefore accessible by the end user.
To "transfer" the values of environment variables to your front-end I would modify your docker image and have a script run as your ENTRYPOINT
that does the following:
echo "var my_env_var = '$MY_ENV_VAR';" >> /usr/share/nginx/html/variables.js
(repeat for each variable)- Load the
variables.js
script in your angular application. - Start nginx in the foreground via
nginx -g 'daemon off;'