aboutsummaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2020-12-14 18:50:56 +0000
committerGravatar Joe Banks <[email protected]>2020-12-14 18:50:56 +0000
commit4fbf9cc45b0d8bbc0341eb1f7f170d0e344ce507 (patch)
treebdb86c41564ccf5bc32a02a855488a86f0f964f6 /backend
parentSwap out list of regex for single regex (diff)
Change how the ALLOWED_HOSTS environment variable sets CORS
Diffstat (limited to 'backend')
-rw-r--r--backend/__init__.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/backend/__init__.py b/backend/__init__.py
index 0eddde0..f285166 100644
--- a/backend/__init__.py
+++ b/backend/__init__.py
@@ -9,13 +9,14 @@ from backend.authentication import JWTAuthenticationBackend
from backend.route_manager import create_route_map
from backend.middleware import DatabaseMiddleware
+HOSTS_REGEX = r"https://(?:(?:(?:.*--)?pydis-forms\.netlify\.app)|forms\.pythondiscord\.com)"
+HAS_CUSTOM_HOST = os.getenv("ALLOWED_URL") is not None
+
middleware = [
Middleware(
CORSMiddleware,
- allow_origins=[
- os.getenv("ALLOWED_URL", "https://forms.pythondiscord.com"),
- ],
- allow_origin_regex=r"https://(?:.*--)?pydis-forms\.netlify\.app/",
+ allow_origins=[os.getenv("ALLOWED_URL")] if HAS_CUSTOM_HOST else None,
+ allow_origin_regex=HOSTS_REGEX if not HAS_CUSTOM_HOST else None,
allow_headers=[
"Authorization",
"Content-Type"