From 196c141f2b72c0529ed4e8dfe4dff250fb203cbc Mon Sep 17 00:00:00 2001 From: Bryan Wilson Date: Mon, 11 Dec 2023 13:55:00 -0800 Subject: [PATCH] Add alternative domains to ALLOWED_HOSTS need to allow requests from customer custom domains --- openedx/core/djangoapps/appsembler/sites/apps.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/openedx/core/djangoapps/appsembler/sites/apps.py b/openedx/core/djangoapps/appsembler/sites/apps.py index cf918385307f..09f4118b7c8a 100644 --- a/openedx/core/djangoapps/appsembler/sites/apps.py +++ b/openedx/core/djangoapps/appsembler/sites/apps.py @@ -12,11 +12,20 @@ def ready(self): from openedx.core.djangoapps.site_configuration.models import SiteConfiguration from django.contrib.sites.models import Site from django.conf import settings + from django.core.exceptions import ObjectDoesNotExist from .config_values_modifier import init_configuration_modifier_for_site_config pre_save.connect(patched_clear_site_cache, sender=SiteConfiguration) post_init.connect(init_configuration_modifier_for_site_config, sender=SiteConfiguration) # Update ALLOWED_HOSTS based on Site model - site_domains = [site.domain for site in Site.objects.all()] + site_domains = [] + sites = Site.objects.all() + for site in sites: + site_domains.append(site.domain) + try: + alt_domain = site.alternative_domain + site_domains.append(alt_domain) + except ObjectDoesNotExist: + continue settings.ALLOWED_HOSTS.extend(site_domains)