Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Updated settings.py to dynamically populate ALLOWED_HOSTS using domains from the Django sites. #1384

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cms/envs/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ def get_env_setting(setting):
SITE_NAME = ENV_TOKENS['SITE_NAME']

ALLOWED_HOSTS = [
# TODO: bbeggs remove this before prod, temp fix to get load testing running
"*",
CMS_BASE,
ENV_TOKENS.get('LMS_BASE', ''),
ENV_TOKENS.get('CMS_BASE', ''),
FEATURES.get('PREVIEW_LMS_BASE', '')
]

LOG_DIR = ENV_TOKENS['LOG_DIR']
Expand Down
7 changes: 3 additions & 4 deletions lms/envs/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,9 @@ def get_env_setting(setting):
CMS_BASE = ENV_TOKENS.get('CMS_BASE', 'studio.edx.org')

ALLOWED_HOSTS = [
# TODO: bbeggs remove this before prod, temp fix to get load testing running
"*",
ENV_TOKENS.get('LMS_BASE'),
FEATURES['PREVIEW_LMS_BASE'],
ENV_TOKENS.get('LMS_BASE', ''),
ENV_TOKENS.get('CMS_BASE', ''),
FEATURES.get('PREVIEW_LMS_BASE', '')
]

# allow for environments to specify what cookie name our login subsystem should use
Expand Down
14 changes: 14 additions & 0 deletions openedx/core/djangoapps/appsembler/sites/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,22 @@ 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
bryanlandia marked this conversation as resolved.
Show resolved Hide resolved
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 = []
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)
Loading