diff --git a/lms/envs/production.py b/lms/envs/production.py index 1fd92d68032..9bd2e51c118 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -27,9 +27,7 @@ import yaml from corsheaders.defaults import default_headers as corsheaders_default_headers from django.core.exceptions import ImproperlyConfigured -from django.contrib.sites.models import Site from path import Path as path -from django.conf import settings from openedx.core.djangoapps.plugins import plugin_settings, constants as plugin_constants from openedx.core.lib.derived import derive_settings @@ -212,17 +210,11 @@ def get_env_setting(setting): CMS_BASE = ENV_TOKENS.get('CMS_BASE', 'studio.edx.org') -# Fetching all domain names from the Site model -site_domains = [site.domain for site in Site.objects.all()] - -ALLOWED_HOSTS = site_domains + [ +ALLOWED_HOSTS = [ ENV_TOKENS.get('LMS_BASE', ''), FEATURES.get('PREVIEW_LMS_BASE', '') ] -# Ensure that no empty strings are in ALLOWED_HOSTS -ALLOWED_HOSTS = [host for host in ALLOWED_HOSTS if host] - # allow for environments to specify what cookie name our login subsystem should use # this is to fix a bug regarding simultaneous logins between edx.org and edge.edx.org which can # happen with some browsers (e.g. Firefox) diff --git a/openedx/core/djangoapps/appsembler/sites/apps.py b/openedx/core/djangoapps/appsembler/sites/apps.py index 90e791c716c..cf918385307 100644 --- a/openedx/core/djangoapps/appsembler/sites/apps.py +++ b/openedx/core/djangoapps/appsembler/sites/apps.py @@ -10,8 +10,13 @@ class SitesConfig(AppConfig): def ready(self): from openedx.core.djangoapps.appsembler.sites.models import patched_clear_site_cache from openedx.core.djangoapps.site_configuration.models import SiteConfiguration + from django.contrib.sites.models import Site + from django.conf import settings 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()] + settings.ALLOWED_HOSTS.extend(site_domains)