aboutsummaryrefslogtreecommitdiffstats
path: root/backend/__init__.py
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2021-03-09 08:48:58 +0200
committerGravatar GitHub <[email protected]>2021-03-09 08:48:58 +0200
commit0ec4a370d476f3f8b7453c887b0b02fe83aced9c (patch)
treee7fb0e7a71369affd79222445a35438815ad4cd3 /backend/__init__.py
parentAdd missing "is" to error message (diff)
parentFixes Production URL Constant (diff)
Merge branch 'main' into ks123/role-assigning
Diffstat (limited to 'backend/__init__.py')
-rw-r--r--backend/__init__.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/backend/__init__.py b/backend/__init__.py
index a3704a0..220b457 100644
--- a/backend/__init__.py
+++ b/backend/__init__.py
@@ -7,10 +7,21 @@ from starlette.middleware.cors import CORSMiddleware
from backend import constants
from backend.authentication import JWTAuthenticationBackend
-from backend.route_manager import create_route_map
from backend.middleware import DatabaseMiddleware, ProtectedDocsMiddleware
+from backend.route_manager import create_route_map
from backend.validation import api
+ORIGINS = [
+ r"(https://[^.?#]*--pydis-forms\.netlify\.app)", # Netlify Previews
+ r"(https?://[^.?#]*.forms-frontend.pages.dev)", # Cloudflare Previews
+]
+
+if not constants.PRODUCTION:
+ # Allow all hosts on non-production deployments
+ ORIGINS.append(r"(.*)")
+
+ALLOW_ORIGIN_REGEX = "|".join(ORIGINS)
+
sentry_sdk.init(
dsn=constants.FORMS_BACKEND_DSN,
send_default_pii=True,
@@ -20,13 +31,13 @@ sentry_sdk.init(
middleware = [
Middleware(
CORSMiddleware,
- # TODO: Convert this into a RegEx that works for prod, netlify & previews
- allow_origins=["*"],
+ allow_origins=["https://forms.pythondiscord.com"],
+ allow_origin_regex=ALLOW_ORIGIN_REGEX,
allow_headers=[
- "Authorization",
"Content-Type"
],
- allow_methods=["*"]
+ allow_methods=["*"],
+ allow_credentials=True
),
Middleware(DatabaseMiddleware),
Middleware(AuthenticationMiddleware, backend=JWTAuthenticationBackend()),