Hi all,
We start thinking about how to use the micro-frontend in a multitenancy installation, we want to share with you our first iteration, get feedback and find a way to make a solution for the community.
The proposal
Frontend-platform recommended extending the initialization handler for config runtime, with that in mind, we think to get the site configuration values through a REST API with a new handler (don’t touch config handler to maintain env config and the actual workflow, where each MFE could override it, for example, in account).
In this case, we don’t have to modify the base code on each MFE.
Test Environment
This proposal was tested in a Tutor Maple dev installation with these plugins:
-
tutor-mfe : " easily add micro frontend (MFE) applications on top of an Open edX platform that runs with Tutor"
-
eox-tenant " a multi-tenancy Django app for edx-platform"
In addition, we use a mock API (http://localhost:3000/config/tenant_id) with some config information, which “common” is a config for all MFE
{
{
"id": "tenant-a.lms.mango.edunext.link",
"common": {
"SITE_NAME": "Tenant A",
"LOGO_URL": "https://www.example.com/tiger.png",
"LOGO_TRADEMARK_URL": "https://www.example.com/tiger.png",
"LOGO_WHITE_URL": "https://www.example.com/tiger.png",
"FAVICON_URL": "https://www.example.com/tiger.png",
"LEARNING_BASE_URL": "http://tenant-a.lms.mango.edunext.link:2000",
"LMS_BASE_URL": "http://tenant-a.lms.mango.edunext.link:8000",
"LOGIN_URL": "http://tenant-a.lms.mango.edunext.link:8000/login",
"LOGOUT_URL": "http://tenant-a.lms.mango.edunext.link:8000/logout"
}
},
{
"id": "tenant-b.lms.mango.edunext.link",
"common": {
"SITE_NAME": "Tenant B",
"LOGO_URL": "https://www.example.com/cat.png",
"LOGO_TRADEMARK_URL": "https://www.example.com/cat.png",
"LOGO_WHITE_URL": "https://www.example.com/cat.png",
"FAVICON_URL": "https://www.example.com/cat.png",
"LEARNING_BASE_URL": "http://tenant-b.lms.mango.edunext.link:2000",
"LMS_BASE_URL": "http://tenant-b.lms.mango.edunext.link:8000",
"LOGIN_URL": "http://tenant-b.lms.mango.edunext.link:8000/login",
"LOGOUT_URL": "http://tenant-b.lms.mango.edunext.link:8000/logout"
},
// example add optional variables or specific for a MFE
"auth": {
"INFO_EMAIL": "diana.olarte@edunext.co"
}
}
Steps to follow
In frontend-platform
We fork frontend-platform for testing purposes and make some modifications (you can look it out below), following the next steps:
- Create a new config variable to know if is a multitenant instance or not; this could be set in the env settings (like default config).
MULTITENANT_API: true
-
Create a function (getHttpConfig) to call the API with the config. We think it’s a good idea to use the cache system.
-
Create a handler for the initialize method (we call that configTenant).
-
Add validation in the initialize to call one of the handlers: config or configTenant.
You can check the first version of the code here (we’re happy to get feedback )
Note: We use module.config.js to develop these changes and test frontend-platform.
In the tenant config of Django Admin
We found out it’s possible to config the URL through the tenant settings like this:
{
"ACCOUNT_MICROFRONTEND_URL": "http://tenant-b.lms.mango.edunext.link:1997/account",
"ENABLE_PROFILE_MICROFRONTEND": true,
"LEARNING_MICROFRONTEND_URL": "http://tenant-b.lms.mango.edunext.link:2000/learning",
"LMS_BASE": "tenant-b.lms.mango.edunext.link:8000",
"LMS_ROOT_URL": "http://tenant-b.lms.mango.edunext.link:8000",
"PLATFORM_NAME": "Tenant B",
"PROFILE_MICROFRONTEND_URL": "http://tenant-b.lms.mango.edunext.link:1995/profile/u/",
"SITE_NAME": "Tenant B",
}
That’s why we can use the hostname to identify the tenant and the MFE (place in the path URL) to set the specific additional configuration in needed cases.
Finally
Use a mock API with the config of the tenant you want to test (like we explained in the test environment section), change the URL in getHttpConfig to match with your API, and test it!.
The result
We want to share a screenshot of 2 tenants (the result of our test), with different values gotten by an API (mock) in the same MFE:
- The URL
- Logo and favicon
- Site name
Tenant A
Tenant B