Skip to content

feat: MFE configuration at runtime - #335

Merged
davidjoy merged 6 commits into
openedx:masterfrom
eduNEXT:dcoa/runtime-config
Jul 11, 2022
Merged

feat: MFE configuration at runtime#335
davidjoy merged 6 commits into
openedx:masterfrom
eduNEXT:dcoa/runtime-config

Conversation

@dcoa

@dcoa dcoa commented May 19, 2022

Copy link
Copy Markdown
Contributor

Description:

This draft PR serves as a discussion holder for the work of making mfes capable of being configured during runtime instead of during build.

This PR creates a new function to allow runtime configuration through an API call to the platform.

How to test

  • To allow runtime configuration set a new environment variable MFE_CONFIG_API_URL in the env file and add the api url ( To test this you can use the API from this PR or use an external tool to mock the API response).
  • The API should respond with a JSON with the config values:
{
  "SITE_NAME": "Test Site",
  "LOGO_URL": "https://testimage.com/logo.svg",
  "LOGO_TRADEMARK_URL": "https://testimage.com/logo.svg",
  "LOGO_WHITE_URL": "https://testimage.com/logo.svg",
  "FAVICON_URL": "https://testimage.com/favicon.ico",
  "CSRF_TOKEN_API_PATH": "/csrf/api/v1/token",
  "LANGUAGE_PREFERENCE_COOKIE_NAME": "openedx-language-preference",
  "LOGIN_URL": "http://testsite.example.com/login",
  "LOGOUT_URL": "http://testsite.example.com/logout",
   "STUDIO_BASE_URL": "http://studio.example.com",
  "MARKETING_SITE_BASE_URL": "http://testsite.example.com",
  "ORDER_HISTORY_URL": "http://testsite.example.com/orders",
  "REFRESH_ACCESS_TOKEN_ENDPOINT": "http://testsite.example.com/login_refresh",
}
  • The initialize process should work normally.
    Note: You can combine buildtime and runtime configuration

Note: Related information FWG Issue

Merge checklist:

  • Consider running your code modifications in the included example app within frontend-platform. This can be done by running npm start and opening http://localhost:8080/. To test this you can use the API from this PR or use an external tool to mock the API response.
  • Consider testing your code modifications in another local micro-frontend using local aliases configured via the module.config.js file in frontend-build. To test this you can use the API from this PR or use an external tool to mock the API response.
  • Gather some consensus on the approach

Post merge:

  • After the build finishes for the merged commit, verify the new release has been pushed to NPM.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. and removed open-source-contribution PR author is not from Axim or 2U labels May 19, 2022
@openedx-webhooks

openedx-webhooks commented May 19, 2022

Copy link
Copy Markdown

Thanks for the pull request, @dcoa! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label May 20, 2022
@dcoa
dcoa force-pushed the dcoa/runtime-config branch 2 times, most recently from c94e3d3 to c8a8fd9 Compare May 24, 2022 11:54
@natabene

Copy link
Copy Markdown

@dcoa Thank you for your contribution.

@dcoa dcoa changed the title Draft - MFE configuration at runtime Draft - feat: MFE configuration at runtime May 24, 2022
@dcoa
dcoa force-pushed the dcoa/runtime-config branch 2 times, most recently from ae3e1d2 to aaa87ef Compare May 27, 2022 17:10
@dcoa
dcoa force-pushed the dcoa/runtime-config branch from aaa87ef to 94f69d0 Compare May 31, 2022 13:30
@dcoa dcoa changed the title Draft - feat: MFE configuration at runtime feat: MFE configuration at runtime May 31, 2022
@dcoa
dcoa marked this pull request as ready for review May 31, 2022 16:29
@openedx-webhooks openedx-webhooks added needs triage and removed waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels May 31, 2022
@dcoa

dcoa commented May 31, 2022

Copy link
Copy Markdown
Contributor Author

Hi @natabene this PR is ready for review.

@codecov

codecov Bot commented May 31, 2022

Copy link
Copy Markdown

Codecov Report

Merging #335 (b03756d) into master (7c9ace2) will increase coverage by 0.71%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #335      +/-   ##
==========================================
+ Coverage   80.53%   81.24%   +0.71%     
==========================================
  Files          38       38              
  Lines         904      917      +13     
  Branches      169      170       +1     
==========================================
+ Hits          728      745      +17     
+ Misses        164      160       -4     
  Partials       12       12              
Impacted Files Coverage Δ
src/config.js 54.54% <ø> (+18.18%) ⬆️
src/initialize.js 98.46% <100.00%> (+0.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7c9ace2...b03756d. Read the comment docs.

@MaferMazu

Copy link
Copy Markdown

I think this should be on your radar @arbrandes

@dcoa

dcoa commented Jun 3, 2022

Copy link
Copy Markdown
Contributor Author

@natabene could you help me re-run the test, please?

@dcoa

dcoa commented Jun 3, 2022

Copy link
Copy Markdown
Contributor Author

Hi, @davidjoy @adamstankiewicz I'm working on changes to make it possible to read the response of the API to configure frontend applications at runtime, I hope you can check this pr and give us feedback 🙏

I have this openedx/frontend-app-account#603 too to make it possible to change the favicon and the site name in the title tag, could you check it?

@davidjoy davidjoy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still looking and don't have a lot of time today, but wanted to give some early feedback! Will be able to look more closely on Monday.

Comment thread src/initialize.js Outdated

// Configuration
await handlers.config();
if (getConfig().MFE_CONFIG_API_URL) { await runtimeConfig(); } else { await handlers.config(); }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd suggest moving this if statement logic into the default config handler. This logic here would continue to just say await handlers.config(); and we would optionally call the runtimeConfig function if MFE_CONFIG_API_URL exists. That way we enable folks to continue to override all of our default config handling.

Note that currently the config handler is set to noOp, so we'll just need to create a new one similar to auth, analytics, or initError. Let me know if this doesn't make sense!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider this, but many applications have the override handler to marge additional values for that specific MFE (account example), which make even if you have MFE_CONFIG_API_URL don't call the API.

That's why I put it there because you can set that additional values with the API or set by env file.

May be I could move the if into runtimeConfig and call like:

    await handlers.config(); 
    await runtimeConfig(); 

What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes sense. Yeah, how about the version you suggested. That way we preserve any overrides and then layer in the runtime config after. This sounds good:

await handlers.config(); 
await runtimeConfig();

Comment thread src/initialize.test.js Outdated
Comment thread src/initialize.js Outdated
} catch (error) {
// eslint-disable-next-line no-console
console.error('Error with config API', error.message);
setConfig({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should let the MFE keep its build-time configuration rather than using setConfig here. I think it'd be more correct to leave all the build-time config values in there, rather than removing everything but BASE_URL. The way this is now, all the values will start returning undefined instead of whatever's in the build-time config, which will likely be reasonable fallbacks in many cases.

@dcoa dcoa Jun 8, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I can remove the setConfig and allow the use of default build-time values when the API fails.

@dcoa
dcoa requested a review from davidjoy June 9, 2022 14:14
Comment thread src/config.js
LOGO_TRADEMARK_URL: process.env.LOGO_TRADEMARK_URL,
LOGO_WHITE_URL: process.env.LOGO_WHITE_URL,
FAVICON_URL: process.env.FAVICON_URL,
MFE_CONFIG_API_URL: process.env.MFE_CONFIG_API_URL,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this value needs to be added in a few more places. As a way to discover places it should appear, I tried searching for LOGO_TRADEMARK_URL above and noted that config values in this file are also set in:

  • .env.test
  • .env.development
  • setupTest.js

Basically, it needs to be defaulted in those files for completeness sake.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could add the key without value by default because is optional :)

andrey-canon pushed a commit to eduNEXT/frontend-platform that referenced this pull request Jan 24, 2023
andrey-canon pushed a commit to eduNEXT/frontend-platform that referenced this pull request Feb 1, 2023
andrey-canon added a commit to eduNEXT/frontend-platform that referenced this pull request Feb 1, 2023
sambapete pushed a commit to EDUlib/frontend-app-discussions that referenced this pull request Apr 11, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] openedx/frontend-platform#335

This is a backport to Olive of
openedx#377
arbrandes pushed a commit to arbrandes/frontend-app-ora-grading that referenced this pull request May 15, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] openedx/frontend-platform#335
arbrandes pushed a commit to arbrandes/frontend-app-ora-grading that referenced this pull request May 15, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] openedx/frontend-platform#335
arbrandes pushed a commit to arbrandes/frontend-app-communications that referenced this pull request May 19, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Only a single change related to the `LMS_BASE_URL` setting was required.

[1] openedx/frontend-platform#335
ghassanmas pushed a commit to ghassanmas/frontend-app-communications that referenced this pull request May 21, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Only a single change related to the `LMS_BASE_URL` setting was required.

[1] openedx/frontend-platform#335
arbrandes pushed a commit to arbrandes/frontend-app-communications that referenced this pull request May 22, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Only a single change related to the `LMS_BASE_URL` setting was required.

[1] openedx/frontend-platform#335
arbrandes pushed a commit to arbrandes/frontend-app-communications that referenced this pull request May 22, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Only a single change related to the `LMS_BASE_URL` setting was required.

[1] openedx/frontend-platform#335
arbrandes pushed a commit to arbrandes/frontend-app-ora-grading that referenced this pull request May 31, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] openedx/frontend-platform#335
arbrandes pushed a commit to arbrandes/frontend-app-ora-grading that referenced this pull request May 31, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] openedx/frontend-platform#335
arbrandes pushed a commit to arbrandes/frontend-app-communications that referenced this pull request Jun 13, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Only a single change related to the `LMS_BASE_URL` setting was required.

[1] openedx/frontend-platform#335
arbrandes pushed a commit to openedx/frontend-app-communications that referenced this pull request Jun 13, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Only a single change related to the `LMS_BASE_URL` setting was required.

[1] openedx/frontend-platform#335
sambapete pushed a commit to EDUlib/frontend-app-discussions that referenced this pull request Jun 14, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] openedx/frontend-platform#335

This is a backport to Olive of
openedx#377
snglth pushed a commit to Abstract-Tech/community-theme-discussions that referenced this pull request Jul 5, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] openedx/frontend-platform#335

This is a backport to Olive of
openedx#377
sambapete pushed a commit to EDUlib/frontend-app-discussions that referenced this pull request Aug 9, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] openedx/frontend-platform#335

This is a backport to Olive of
openedx#377
sambapete pushed a commit to EDUlib/frontend-app-discussions that referenced this pull request Oct 11, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] openedx/frontend-platform#335

This is a backport to Olive of
openedx#377
sambapete pushed a commit to EDUlib/frontend-app-discussions that referenced this pull request Oct 13, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] openedx/frontend-platform#335

This is a backport to Olive of
openedx#377
moonesque pushed a commit to edSPIRIT/frontend-app-discussions that referenced this pull request Nov 11, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] openedx/frontend-platform#335
moonesque pushed a commit to edSPIRIT/frontend-app-discussions that referenced this pull request Nov 11, 2023
(This reintroduces the change in 9f84230 that was later reverted by
67b0b33.)

frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] openedx/frontend-platform#335
sambapete pushed a commit to EDUlib/frontend-app-discussions that referenced this pull request Nov 17, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] openedx/frontend-platform#335

This is a backport to Olive of
openedx#377
sambapete pushed a commit to EDUlib/frontend-app-discussions that referenced this pull request Dec 11, 2023
frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] openedx/frontend-platform#335

This is a backport to Olive of
openedx#377
becdavid pushed a commit to CUCWD/frontend-platform that referenced this pull request May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project
Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants