-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
APP_INITIALIZER alternative #1
Comments
@ccadieux That's a nice solution! The thing for me was that, since we do builds using something like a GoCD box, I wanted to use OS environment variables. But yeah, this approach might be more pragmatic. It certainly involves fewer lines of code! 🤘 |
In a current project (angular:frontend + django:api-backend) I use Nevertheless for what we are try to solving here https://medium.com/@natchiketa/angular-cli-and-os-environment-variables-4cfa3b849659 I fail to see why your approach with "environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
} I've achieved this in the backend using Did I'm missing something? I'll like your opinions! |
Probably I will end with something different since I'm using ansible, I can generate the env files with the proper settings for the env I'm building |
@jjlorenzo I believe @ccadieux 's answer is was due to what he said in dev ops required that after the build is made no more new builds should be made. If you go with the environment.ts method for each environment you must do a rebuild of the code to be able to properly get the values into the app. I also use configuration.json in APP_INITIALIZER for the exact same reason. After the code is built, no new builds are made as it is being promoted to production. |
@ccadieux you mentioned that you do a single build using this approach. How is the final built code know which environment to load the config for? (i.e. hit uat.example.com/config vs app.example.com/config) |
@kenisteward good catch, your'e right. |
Basically, not much is in the environment file anymore. Everything that can change is in the config file for each environment. |
I am probably missing something. If I have 10 config values that are different between UAT and Production (so they are stored in either 2 different files or in 2 different urls), how does APP_INITIALIZER decide which of the two to load at runtime? Or do you always reference a single file in a specific location and change this file's contents depending on the environment. The reason I am asking is because I would like to load the configuration from a different location depending on the environment. eg. |
my 5 cents, add a property to every |
I agree with @jjlorenzo . If you want to take that approach just do that.
Otherwise just template your config and change that one file.
…On Mon, May 7, 2018, 6:13 PM jjlorenzo ***@***.***> wrote:
my 5 cents, add a property to every environment.ts with the env name, for
example and use this value in the APP_INITIALIZER to determine the url.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMPLtYS9BfhnybLMFAJghYjyCDWNdnOiks5twMb-gaJpZM4N7jev>
.
|
We had similar requirements.
We ended up using APP_INITIALIZER to load a json file with our configuration.
Here's a minimal example: https://embed.plnkr.co/295SxTOZEZUbiyrhAKh2/
Some other links
angular/angular#9047
https://stackoverflow.com/questions/39033835/angularjs2-preload-server-configuration-before-the-application-starts
The text was updated successfully, but these errors were encountered: