Files
plugins/openedx-tenant-api/test_e2e/cors_multitenant.py
DamarKusumo 2b7027e37d Add openedx-tenant-api plugin
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 08:20:57 +07:00

78 lines
2.6 KiB
Python

from tutor import hooks
# CORS fix for multi-tenant local development
# Allows any subdomain of local.openedx.io to make cross-origin requests
hooks.Filters.ENV_PATCHES.add_item(
(
"openedx-lms-common-settings",
"""
# CORS fix for multi-tenant local development
CORS_ORIGIN_REGEX_WHITELIST = [
# Match: *.local.openedx.io and *.*.local.openedx.io (e.g., tenant.apps.local.openedx.io)
r"^http://([a-zA-Z0-9-]+\.)?local\.openedx\.io(:[0-9]+)?$",
r"^http://([a-zA-Z0-9-]+\.)?apps\.local\.openedx\.io(:[0-9]+)?$",
]
# Also add to CORS_ORIGIN_WHITELIST for explicit ports
CORS_ORIGIN_WHITELIST.extend([
"http://apps.local.openedx.io:1995", # Profile MFE
"http://apps.local.openedx.io:1996", # Learner Dashboard MFE
"http://apps.local.openedx.io:1997", # Account MFE
"http://apps.local.openedx.io:1999", # Authn MFE
"http://apps.local.openedx.io:2000", # Learning MFE
"http://apps.local.openedx.io:2001", # Authoring MFE
"http://apps.local.openedx.io:2002", # Discussions MFE
"http://apps.local.openedx.io:2025", # Communications MFE
])
CSRF_TRUSTED_ORIGINS.extend([
"http://apps.local.openedx.io:1995",
"http://apps.local.openedx.io:1996",
"http://apps.local.openedx.io:1997",
"http://apps.local.openedx.io:1999",
"http://apps.local.openedx.io:2000",
"http://apps.local.openedx.io:2001",
"http://apps.local.openedx.io:2002",
"http://apps.local.openedx.io:2025",
])
"""
)
)
hooks.Filters.ENV_PATCHES.add_item(
(
"openedx-cms-common-settings",
"""
# CORS fix for multi-tenant local development
CORS_ORIGIN_REGEX_WHITELIST = [
# Match: *.local.openedx.io and *.*.local.openedx.io (e.g., tenant.apps.local.openedx.io)
r"^http://([a-zA-Z0-9-]+\.)?local\.openedx\.io(:[0-9]+)?$",
r"^http://([a-zA-Z0-9-]+\.)?apps\.local\.openedx\.io(:[0-9]+)?$",
]
CORS_ORIGIN_WHITELIST.extend([
"http://apps.local.openedx.io:1995",
"http://apps.local.openedx.io:1996",
"http://apps.local.openedx.io:1997",
"http://apps.local.openedx.io:1999",
"http://apps.local.openedx.io:2000",
"http://apps.local.openedx.io:2001",
"http://apps.local.openedx.io:2002",
"http://apps.local.openedx.io:2025",
])
CSRF_TRUSTED_ORIGINS.extend([
"http://apps.local.openedx.io:1995",
"http://apps.local.openedx.io:1996",
"http://apps.local.openedx.io:1997",
"http://apps.local.openedx.io:1999",
"http://apps.local.openedx.io:2000",
"http://apps.local.openedx.io:2001",
"http://apps.local.openedx.io:2002",
"http://apps.local.openedx.io:2025",
])
"""
)
)