[WP] 14.03.2023 | environments

 

fig 1.1 enviroments example diagram

-----------------------------------------------------------------------

Environment is a single deploy with determined config. Basic examples of environments are development environment, staging environment, testing environment and production environment. SPA config is everything that is likely to vary between deploys. Information such as backend-API keys, Analitics-API(eg. datadog) keys, error reporting-API(eg. Sentry) keys, database url or json web token secret. Eg analytics are not required during development so it is disabled in development config file.


There are three ways to manage config in frontend application. The first is injection during buildtime. Each environment is deployed on separate container as separate docker image. All environmental variables are injected to appropriate image during buildtime. This kind approach increase safety of passed information as potential hacker do not know what kind of environments exist. The second possibility is to iclude environmetnal variables within application codebase. The user need to prepare config.json file for each intended environment and import it to a single file. After that choose appropriate config depending on window.location.hostname value using conditional statement if/elif/else or switch statement. Additionaly common parts of any two config objects may be abstracted and merged after a conditional statement. Prepared config.json file should be consumed within main app component. The third solution is fetching config file from the internet – it is dependant on a good internet singal.


Finally it is important not to expose any API keys within public repository. There are many cases of application exposure bacause of uploading api/database_url into a public github repository.


climbing up

gmarcin


Komentarze

Popularne posty z tego bloga

[WP] 23.06.2023 | subjects

15.07.2024 | simplicity

[WP] 05.06.2023 | angular-intro