aboutsummaryrefslogtreecommitdiffstats
path: root/backend/__init__.py
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2021-03-08 14:26:25 +0300
committerGravatar Hassan Abouelela <[email protected]>2021-03-08 14:29:58 +0300
commit3f2f8ca1900a4651b1831bef65f4eb324e138538 (patch)
tree7808d2596bebb0201a8ec5a4ae32d1fa3100df79 /backend/__init__.py
parentMerge branch 'main' into dependabot/pip/sentry-sdk-0.20.3 (diff)
parentMerge pull request #69 from python-discord/dependabot/pip/flake8-annotations-... (diff)
Merge branch 'main' into dependabot/pip/sentry-sdk-0.20.3
Signed-off-by: Hassan Abouelela <[email protected]> # Conflicts: # backend/__init__.py # poetry.lock
Diffstat (limited to 'backend/__init__.py')
-rw-r--r--backend/__init__.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/backend/__init__.py b/backend/__init__.py
index e629e82..dcbdcdf 100644
--- a/backend/__init__.py
+++ b/backend/__init__.py
@@ -11,6 +11,17 @@ 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_RELEASE = f"forms-backend@{constants.GIT_SHA}"
sentry_sdk.init(
dsn=constants.FORMS_BACKEND_DSN,
@@ -22,13 +33,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()),