runtime-config-loader 6.0.0 → 6.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.
- package/README.md +31 -32
- package/package.json +1 -1
- package/runtime-config-loader-6.0.1.tgz +0 -0
- package/runtime-config-loader-6.0.0.tgz +0 -0
package/README.md
CHANGED
|
@@ -8,51 +8,50 @@ This library provides an easy way to load one or more JSON files with configurat
|
|
|
8
8
|
|
|
9
9
|
## How to Implement
|
|
10
10
|
|
|
11
|
-
In your `app.
|
|
11
|
+
In your `app.config.ts` file, add the following to the `providers` array:
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
|
|
14
|
+
import { provideRuntimeConfig } from 'runtime-config-loader';
|
|
15
|
+
|
|
16
|
+
export const appConfig: ApplicationConfig = {
|
|
17
|
+
providers: [
|
|
18
|
+
...,
|
|
19
|
+
provideRuntimeConfig({ configUrl: './assets/config.json' }),
|
|
20
|
+
...
|
|
21
|
+
]
|
|
22
|
+
};
|
|
15
23
|
```
|
|
16
24
|
|
|
17
|
-
That's it; it's that simple.
|
|
25
|
+
That's it; it's that simple. The `provideRuntimeConfig` function sets up the `APP_INITIALIZER` token to load the configuration from a file or an API endpoint before the application starts.
|
|
18
26
|
|
|
19
|
-
|
|
27
|
+
### Configuration
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
imports: [
|
|
23
|
-
...,
|
|
24
|
-
RuntimeConfigLoaderModule.forRoot(
|
|
25
|
-
{ configUrl: './path/to/config/config.json' }
|
|
26
|
-
),
|
|
27
|
-
...]
|
|
28
|
-
```
|
|
29
|
+
The `provideRuntimeConfig` function accepts a configuration object with a `configUrl` property. This can be a single string or an array of strings.
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
#### Single Config File
|
|
32
|
+
|
|
33
|
+
The default location is `./assets/config.json`. If you'd like to load the file from a different location:
|
|
31
34
|
|
|
32
35
|
```ts
|
|
33
|
-
|
|
34
|
-
...,
|
|
35
|
-
RuntimeConfigLoaderModule.forRoot(
|
|
36
|
-
{ configUrl: ['./path/to/config/config-1.json', './path/to/config/config-2.json'] }
|
|
37
|
-
),
|
|
38
|
-
...]
|
|
36
|
+
provideRuntimeConfig({ configUrl: './path/to/config/config.json' });
|
|
39
37
|
```
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
## Multiple Config Paths
|
|
39
|
+
#### Multiple Config Files
|
|
44
40
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
It's important to know that if an attribute is repeated in two configuration files, the latest value is kept. So, let's say you have `apiUrl` in both files, `config-1.json` and `config-2.json`. Let's assume the files are passed in to the `forRoot` method like this:
|
|
41
|
+
You can load multiple files (or API endpoints) and they will be merged into a single configuration object.
|
|
48
42
|
|
|
49
43
|
```ts
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
provideRuntimeConfig({
|
|
45
|
+
configUrl: [
|
|
46
|
+
'./path/to/config/config-1.json',
|
|
47
|
+
'./path/to/config/config-2.json',
|
|
48
|
+
],
|
|
49
|
+
});
|
|
56
50
|
```
|
|
57
51
|
|
|
58
|
-
|
|
52
|
+
If an attribute is repeated in multiple configuration files, the latest value is kept. For example, if `apiUrl` exists in both files above, the value from `config-2.json` will override the value from `config-1.json`.
|
|
53
|
+
|
|
54
|
+
> [!TIP]
|
|
55
|
+
> This is useful for maintaining local overrides (e.g., `local.config.json` ignored by git) or separating environment-specific values from global ones.
|
|
56
|
+
|
|
57
|
+
Make sure that the path(s) you provide are accessible by the Angular application. The `assets` folder is generally the easiest place to serve these files.
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|