-
Notifications
You must be signed in to change notification settings - Fork 12k
Runtime Environment Settings #7506
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
Comments
This can be achieved currently without any modifications to the CLI. One method would be to create an application configuration service (e.g., An additional CLI feature that could be useful in this scenario (and potentially others), would be to expand the environment option to allow the addition of assets per environment. Allowing, for instance, a production environment to add a different set of files to the output than a development or staging environment. However, with the defaulting concept as explained above, this not necessarily a requirement but simply opens up an additional implementation option for the desired use case. |
my 2c, I swear by 12factors Config in my apps, and I totally like having run-time control from environment variables. With a client side app you don't actually have control of the runtime environments. In practice, I've found run time setting definition difficult in for ng apps, specifically the startup delay when your app has to go look up configuration. Usually, I set environment at build time and package unique dev, qa, and prod assets. As a developer I try to ensure the only things that charge are configuration settings and include/exclude dev instrumentation. |
Agree with this 1000%. In AngularJS apps, I've usually deployed them on PHP/Python/ASP.net MVC server with just one "backend" controller that served up a JS file populating a global |
It is not: turn off files hashing (do not turn off for "media") (use hashing on PHP side), add scripts to Print your "config" in the script tag before first script tag. <script>
APP_CONFIG = {};
</script> Create provider token and provide your config via factory. export const APP_CONFIG_TOKEN = new InjectionToken<string>('APP_CONFIG_TOKEN');
export function appConfigFactory() {
return (window as any).APP_CONFIG;
}
//...
{provide: APP_CONFIG_TOKEN, useFactory: appConfigFactory} |
Also you can use Webpack's dynamic imports to achieve that. Manually put
You can call it from FWIW there are many relatively simple ways to achieve runtime environment settings. |
My answer above allows for runtime settings without the need for a backend service, modifying index.html, or using webpack specific features. The key is to use an angular service to request the JSON file either on startup or on first use via the angular http service. In my projects I also add additional logic to the service to incorporate the CLI environment options, provide option defaults and helper functions, etc. |
@clydin Would you mind giving more details on how you implement that? I'm coming fresh from an AngularJS world and I don't know Angular 4 specifics as well as I probably should. I understand how you would request a JSON file via |
Google for examples of using |
@devoto13 I got this working on my app and it worked great until I brought in I'll play around some more...maybe this an issue I should file with the ngrx team. |
Regarding |
I think the workaround sounds quite reasonable/usable, closing this issue/feature request. |
Heya all, just want to mention that this issue was essentially a duplicate of #3855, and there's some more discussion there. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)Versions.
@angular/cli: 1.3.2
node: 7.8.0
os: darwin x64
Repro steps.
Not a failure.
The log given by the failure.
Not a failure
Desired functionality.
With modern DevOps and infrastructure automation, it is easy to create a new environment on the fly. To better support this new world, it would be preferred to have one build package and provide the configuration at the point of deployment. This is a more flexible model, which fits a more dynamic environment.
Imagine you are trying to reproduce an issue, but you need to have a copy of production to duplicate the issue, as it only shows up in production. With modern infrastructure tools, it is easy to create a replica of production in the cloud and all the other services on the Internet. With the current design the following steps are required to create a new environment:
evironment.{env}.ts
file from the new settings of step 1In the process above, you risk creating a build that differs from the one in production, which could cause issues and loss of time. The new environment services are first, since you may get tokens and other settings from these services, which need to go into the environment file. This design requires knowledge of all your environments to be known and static, which is fine in a small project, but it is inflexible in this modern era.
By using a runtime environment settings, we reduce the need to create a new environment file and build, which may lead to issues. Here is an example flow for runtime environment settings:
In this example, the new environment has an exact copy of the build package, not a new build. Runtime environment settings, allow for easy creation of new environments to meet current project needs.
Mention any other details that might be useful.
Nothing else to add.
The text was updated successfully, but these errors were encountered: