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

feat: add mfe config api #30473

Merged
merged 10 commits into from
Jul 8, 2022
Prev Previous commit
Next Next commit
docs: add the ADR
  • Loading branch information
MaferMazu committed Jul 8, 2022
commit d6a30882d157474f9c76ccb6731470dd2ab7cc5e
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
0001 MFE CONFIG API
####################

Status
******

Accepted

Context
*******

Currently, MFE settings are set via command line environment variables or an .env file that is read during the build process, causing the operators to rebuild mfes each time when any variables are changed. The creation of the ``mfe_config_api`` allows configuration at runtime and avoids rebuilds.
`MFE Configuration during Runtime`_.

Decision
********

- A lightweight API will be created that returns the mfe configuration variables from the site configuration.
- The API will be enabled or disabled using the setting ``ENABLE_MFE_CONFIG_API``.
- The API will take the mfe configuration in the ``MFE_CONFIG`` keyset in the site configuration (admin > site configuration > your domain).
- This API allows to consult the configurations by specific MFE. Making a request like ``api/v1/mfe_config?mfe=mymfe`` will return the configuration defined in ``MFE_CONFIG_MYMFE`` merged with the ``MFE_CONFIG`` configuration.
- The API will have a mechanism to cache the response with ``MFE_CONFIG_API_CACHE_TIMEOUT`` variable.
- The API will live in lms/djangoapps because this is not something Studio needs to serve and it is a lightweight API. `PR Discussion`_
- The API will not require authentication or authorization.
- The API request and response will be like:

Request::

GET http://lms.base.com/api/v1/mfe_config?mfe=learning

Response::

{
"BASE_URL": "https://name_of_mfe.example.com",
"LANGUAGE_PREFERENCE_COOKIE_NAME": "example-language-preference",
"CREDENTIALS_BASE_URL": "https://credentials.example.com",
"DISCOVERY_API_BASE_URL": "https://discovery.example.com",
"LMS_BASE_URL": "https://courses.example.com",
"LOGIN_URL": "https://courses.example.com/login",
"LOGOUT_URL": "https://courses.example.com/logout",
"STUDIO_BASE_URL": "https://studio.example.com",
"LOGO_URL": "https://courses.example.com/logo.png"

}

Consequences
************

- We have to change all the mfes so that they take the information from the API. `Issue MFE runtime configuration in frontend-wg`_
- Initialize the MFE could have a delay due to the HTTP method.
- `Site configuration is going to be deprecated`_ so later we have to take the configuration from django settings.
- The operator is responsible for configuring the settings in site configuration.
- We can have duplicate keys in site configuration (example: we can have a logo definition for each mfe).
- If the request is made from a domain that does not have a site configuration, it returns an empty json.

Rejected Alternatives
**********************

- It was not made as a plugin or IDA because it is a lightweight implementation `PR Discussion`_

References
**********

.. _MFE Configuration during Runtime: https://docs.google.com/document/d/1-FHIQmyeQZu3311x8eYUNMru4JX7Yb3UlqjmJxvM8do/edit?usp=sharing

.. _PR Discussion: https://github.com/openedx/edx-platform/pull/30473#issuecomment-1146176151

.. _Site configuration is going to be deprecated: https://github.com/openedx/platform-roadmap/issues/21

.. _Issue MFE runtime configuration in frontend-wg: https://github.com/openedx/frontend-wg/issues/103