Skip to content

Commit 1c5b644

Browse files
committed
docs: improving documentation around when to use config methods
Based on PR feedback - be clearer about how the configuration methods overlap and what their best use cases are.
1 parent 18940ad commit 1c5b644

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

docs/decisions/0007-javascript-file-configuration.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ JavaScript file configuration is compatible with runtime MFE configuration.
113113
frontend-platform loads configuration in a predictable order:
114114

115115
- environment variable config
116-
- optional handlers (used to merge MFE-specific config in via additional
116+
- optional handlers (commonly used to merge MFE-specific config in via additional
117117
process.env variables)
118118
- JS file config
119119
- runtime config
@@ -125,7 +125,6 @@ In the future if we deprecate environment variable config, it's likely that
125125
we keep both JS file config and runtime configuration around. JS file config
126126
primarily to handle extensibility, and runtime config for everything else.
127127

128-
129128
Rejected Alternatives
130129
---------------------
131130

src/config.js

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,27 @@
22
* #### Import members from **@edx/frontend-platform**
33
*
44
* The configuration module provides utilities for working with an application's configuration
5-
* document (ConfigDocument). Configuration environment variables can be supplied to the
6-
* application in four different ways:
5+
* document (ConfigDocument). Configuration variables can be supplied to the
6+
* application in four different ways. They are applied in the following order:
77
*
8-
* ##### Build-time Environment Variables
8+
* - Build-time Configuration
9+
* - Environment Variables
10+
* - JavaScript File
11+
* - Runtime Configuration
12+
*
13+
* Last one in wins. Variables with the same name defined via the later methods will override any
14+
* defined using an earlier method. i.e., if a variable is defined in Runtime Configuration, that
15+
* will override the same variable defined in either Build-time Configuration method (environment
16+
* variables or JS file). Configuration defined in a JS file will override environment variables.
17+
*
18+
* ##### Build-time Configuration
19+
*
20+
* Build-time configuration methods add config variables into the app when it is built by webpack.
21+
* This saves the app an API call and means it has all the information it needs to initialize right
22+
* away. There are two methods of supplying build-time configuration: environment variables and a
23+
* JavaScript file.
24+
*
25+
* ######Environment Variables
926
*
1027
* A set list of required config variables can be supplied as
1128
* command-line environment variables during the build process.
@@ -19,12 +36,23 @@
1936
* Note that additional variables _cannot_ be supplied via this method without using the `config`
2037
* initialization handler. The app won't pick them up and they'll appear `undefined`.
2138
*
22-
* ##### JavaScript File Configuration
39+
* This configuration method is being deprecated in favor of JavaScript File Configuration.
2340
*
24-
* Configuration variables can be supplied in an optional file
25-
* named env.config.js. This file must export either an Object containing configuration variables
26-
* or a function. The function must return an Object containing configuration variables or,
27-
* alternately, a promise which resolves to an Object.
41+
* ###### JavaScript File Configuration
42+
*
43+
* Configuration variables can be supplied in an optional file named env.config.js. This file must
44+
* export either an Object containing configuration variables or a function. The function must
45+
* return an Object containing configuration variables or, alternately, a promise which resolves to
46+
* an Object.
47+
*
48+
* Using a function or async function allows the configuration to be resolved at runtime (because
49+
* the function will be executed at runtime). This is not common, and the capability is included
50+
* for the sake of flexibility.
51+
*
52+
* JavaScript File Configuration is well-suited to extensibility use cases or component overrides,
53+
* in that the configuration file can depend on any installed JavaScript module. It is also the
54+
* preferred way of doing build-time configuration if runtime configuration isn't used by your
55+
* deployment of the platform.
2856
*
2957
* Exporting a config object:
3058
* ```
@@ -59,15 +87,20 @@
5987
*
6088
* ##### Runtime Configuration
6189
*
62-
* Configuration variables can also be supplied using the "runtime
63-
* configuration" method, taking advantage of the Micro-frontend Config API in edx-platform.
64-
* More information on this API can be found in the ADR which introduced it:
90+
* Configuration variables can also be supplied using the "runtime configuration" method, taking
91+
* advantage of the Micro-frontend Config API in edx-platform. More information on this API can be
92+
* found in the ADR which introduced it:
6593
*
6694
* https://github.com/openedx/edx-platform/blob/master/lms/djangoapps/mfe_config_api/docs/decisions/0001-mfe-config-api.rst
6795
*
6896
* The runtime configuration method can be enabled by supplying a MFE_CONFIG_API_URL via one of the other
6997
* two configuration methods above.
7098
*
99+
* Runtime configuration is particularly useful if you need to supply different configurations to
100+
* a single deployment of a micro-frontend, for instance. It is also a perfectly valid alternative
101+
* to build-time configuration, though it introduces an additional API call to edx-platform on MFE
102+
* initialization.
103+
*
71104
* ##### Initialization Config Handler
72105
*
73106
* The configuration document can be extended by

0 commit comments

Comments
 (0)