Skip to content
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

Angular: Read settings from Json files #4386

Closed
rachanee-mwp opened this issue Jun 18, 2020 · 6 comments · Fixed by #4967
Closed

Angular: Read settings from Json files #4386

rachanee-mwp opened this issue Jun 18, 2020 · 6 comments · Fixed by #4967

Comments

@rachanee-mwp
Copy link
Contributor

rachanee-mwp commented Jun 18, 2020

Please modify Angular modules to read settings from Json files instead of environment.ts to allow overwriting settings in CD process, for instance change API Url per deploying environment.
We saw the implementation of AppPreBootstrap which load settings from Json in ASP.NET Zero and tried to implement the logic in AbpCommercial but could not make it work somehow.

@armanozak
Copy link
Contributor

Hi @rachanee-mwp,

We cannot read settings from JSON files instead of environment files, because as described here this is the default and common way of getting application setup in Angular. There is also a request to ABP backend at application start, which receives specific application configuration for a user.

If those two do not resolve the requirement in your case, you can use one of Angular's predefined tokens and make an Http request within the token factory. After getting the configuration, you can keep it in a singleton service or pass it to a state for further use.

Please take a look at this article on using an APP_INITIALIZER token. The most common one is the APP_INITIALIZER, but depending on the scenario, PLATFORM_INITIALIZER or APP_BOOTSTRAP_LISTENER may prove to be a better choice.

I wish that answers your question. Please let me know if all is clear.

Have a nice day.

@mehmet-erim mehmet-erim modified the milestone: 3.0 Jun 23, 2020
@rachanee-mwp
Copy link
Contributor Author

Hi @armanozak

Thanks for clarifying and giving list of potential solutions.
The last option which mentions APP_INITIALIZER token is what I'm talking about.
You implement this on ASP.NET Zero and we want the same on AbpCommercial.

image
image
image

@armanozak armanozak added this to the backlog milestone Jun 24, 2020
@armanozak
Copy link
Contributor

armanozak commented Jun 24, 2020

Hi @rachanee-mwp,

Looking for same tools you have in ASP.NET Zero is perfectly understandable. We will consider this as a feature request and will have to discuss if/when/how we should implement such a feature.

I have marked this issue as a feature and added it to the backlog. Yet, since there already is an easy way to do that yourself, I expect this feature to be considered as a relatively low priority one compared to other issues on our roadmap.

If, in the meantime, you come up with a solution that the whole community can benefit from, please do share with us. As long as it suits public use and does not break the current structure of the project, we would most certainly welcome your PR.

Thanks for your contribution.

@rachanee-mwp
Copy link
Contributor Author

@armanozak

Thanks for considering this as a future feature.

Actually, I have tried to implement the APP_INITIALIZER in AbpCommercial by changing apis.default.url but Abp components are not using the new value. They still connect to the Api URL specified in environment.ts.

@olicooper
Copy link
Contributor

related #3536

@olicooper
Copy link
Contributor

olicooper commented Aug 4, 2020

I created something that reads from a json file env.json. I also use a package called deepmerge to replace nested properties in environment.ts with whatever you want and also append new properties.

Its not a production quality implementation but it does the job. The process is roughly as below (works with ABP v3.0.x):

  1. Create the environment-config.module.ts
  2. Create the extended-config.state.ts
  3. Add the EnvironmentConfig module to your main app.module.ts
    OAuthModule.forRoot(),
    CoreModule.forRoot({
      environment,
      skipGetAppConfiguration: true,
    }),

    EnvironmentConfigModule.forRoot({
      configUrl: '/env.json'
    }),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants