runtime-config-loader 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +27 -4
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,7 +1,30 @@
1
- # runtime-config-loader
1
+ # Angular Runtime Configuration Loader
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ Most applications require certain configuration values that can be changed at runtime of the app. The `environment.ts` files in an Angular application technically work for setting configuration values in an app, but those are buildtime configuration values. This means that they are set when the application is built, and can't be changed unless the app is built again.
4
4
 
5
- ## Running unit tests
5
+ ## Overview
6
6
 
7
- Run `nx test runtime-config-loader` to execute the unit tests.
7
+ This library provides an easy way to load a JSON file with configuration values or make an HTTP GET call to an API endpoint that returns those values. You can then use that configuration throughout the application. The default location of the JSON file is in the `assets` folder, at `./assets/config.json`. When the service loads the file, it stores that configuration object in a local variable which can be accessed via the `getConfig()` and `getConfigObjectKey(key: string)` methods. `getConfig` returns the entire configuration object; `getConfigObjectKey(key: string)` returns part of the configuration object, namely the part defined by the key passed in. In some cases, the `config.json` is not finished loading before other modules/services are, so the above methods will return null. If that is the case, subscribe to the `configSubject` and access the configuration object that way.
8
+
9
+ ## How to Implement
10
+
11
+ In your `app.module.ts` file, add the following to the `@NgModule` decorator:
12
+
13
+ ```ts
14
+ imports: [..., RuntimeConfigLoaderModule, ...],
15
+ ```
16
+
17
+ That's it; it's that simple. In the `RuntimeConfigLoaderModule`, the `APP_INITIALIZER` token is used to run a function which loads the configuration from a file or an API endpoint that can be used throughout the application.
18
+
19
+ If you implement the library exactly as it is above, the configuration file needs to be in the `./assets/config.json` location as mentioned above. If you'd like to load the file from a different location, provide that location in the `.forRoot()` method when importing the `RuntimeConfigLoaderModule`:
20
+
21
+ ```js
22
+ imports: [
23
+ ...,
24
+ RuntimeConfigLoaderModule.forRoot(
25
+ { configUrl: './path/to/config/config.json' }
26
+ ),
27
+ ...]
28
+ ```
29
+
30
+ Make sure that the path you provide here is accessible by the Angular application, meaning that the file is somewhere the app can load it. In my opinion, the `assets` folder is the easiest place to work from.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runtime-config-loader",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "author": {
5
5
  "email": "preston.j.lamb@gmail.com",
6
6
  "name": "Preston Lamb",