* This changes the API's path. The reasoning is that this is Version 1 of the mfe_config API, not Version 1 of the LMS's entire API, so the v1 should come after mfe_config. * Why does this matter? Firstly, consistency. Secondly, it affects our generated API documentation. If you visited https://courses.edx.org/api-docs, you could see that the API was listed under "v1" instead of "mfe_config".
72 lines
2.4 KiB
Python
72 lines
2.4 KiB
Python
"""
|
|
MFE API Views for useful information related to mfes.
|
|
"""
|
|
|
|
import edx_api_doc_tools as apidocs
|
|
from django.conf import settings
|
|
from django.http import HttpResponseNotFound, JsonResponse
|
|
from django.utils.decorators import method_decorator
|
|
from django.views.decorators.cache import cache_page
|
|
from rest_framework import status
|
|
from rest_framework.views import APIView
|
|
|
|
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
|
|
|
|
|
class MFEConfigView(APIView):
|
|
"""
|
|
Provides an API endpoint to get the MFE configuration from settings (or site configuration).
|
|
"""
|
|
|
|
@method_decorator(cache_page(settings.MFE_CONFIG_API_CACHE_TIMEOUT))
|
|
@apidocs.schema(
|
|
parameters=[
|
|
apidocs.query_parameter(
|
|
'mfe',
|
|
str,
|
|
description="Name of an MFE (a.k.a. an APP_ID).",
|
|
),
|
|
],
|
|
)
|
|
def get(self, request):
|
|
"""
|
|
Return the MFE configuration, optionally including MFE-specific overrides.
|
|
|
|
**Usage**
|
|
|
|
Get common config:
|
|
GET /api/mfe_config/v1
|
|
|
|
Get app config (common + app-specific overrides):
|
|
GET /api/mfe_config/v1?mfe=name_of_mfe
|
|
|
|
**GET Response Values**
|
|
```
|
|
{
|
|
"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",
|
|
... and so on
|
|
}
|
|
```
|
|
"""
|
|
|
|
if not settings.ENABLE_MFE_CONFIG_API:
|
|
return HttpResponseNotFound()
|
|
|
|
mfe_config = configuration_helpers.get_value('MFE_CONFIG', settings.MFE_CONFIG)
|
|
if request.query_params.get('mfe'):
|
|
mfe = str(request.query_params.get('mfe'))
|
|
app_config = configuration_helpers.get_value(
|
|
'MFE_CONFIG_OVERRIDES',
|
|
settings.MFE_CONFIG_OVERRIDES,
|
|
)
|
|
mfe_config.update(app_config.get(mfe, {}))
|
|
return JsonResponse(mfe_config, status=status.HTTP_200_OK)
|