intent/config/settings/prod.py

38 lines
1.3 KiB
Python
Raw Normal View History

import os
import sentry_sdk
from django.core.exceptions import ImproperlyConfigured
from .base import * # noqa: F403
if not SECRET_KEY: # noqa: F405
raise ImproperlyConfigured("DJANGO_SECRET_KEY must be set")
# The console backend would print sign-in codes and invite links into the logs.
if EMAIL_BACKEND == "django.core.mail.backends.console.EmailBackend": # noqa: F405
raise ImproperlyConfigured("EMAIL_BACKEND must be set to a real email backend in production")
ALLOWED_HOSTS = [h for h in os.environ.get("DJANGO_ALLOWED_HOSTS", "").split(",") if h]
CSRF_TRUSTED_ORIGINS = [f"https://{h}" for h in ALLOWED_HOSTS]
# Fly terminates TLS and forwards the original scheme.
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
# Short until the domain is settled; raise to a year after launch.
SECURE_HSTS_SECONDS = 60 * 60 * 24
MIDDLEWARE = [*MIDDLEWARE] # noqa: F405
MIDDLEWARE.insert(
MIDDLEWARE.index("django.middleware.security.SecurityMiddleware") + 1,
"whitenoise.middleware.WhiteNoiseMiddleware",
)
STORAGES = {
**STORAGES, # noqa: F405
"staticfiles": {"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage"},
}
if dsn := os.environ.get("SENTRY_DSN"):
sentry_sdk.init(dsn=dsn, send_default_pii=False, traces_sample_rate=0)