allow to disable redirect
All checks were successful
Build and Deploy / build (push) Successful in 1m11s
Django Tests / test (push) Successful in 1m10s
Build and Deploy / deploy (push) Successful in 4s

This commit is contained in:
Tobias Brunner 2025-07-16 10:18:18 +02:00
parent a4a0fa4f8b
commit 6c884b7804
No known key found for this signature in database
2 changed files with 3 additions and 3 deletions

View file

@ -6,12 +6,11 @@ from urllib.parse import urlparse
class PrimaryDomainRedirectMiddleware:
def __init__(self, get_response):
self.get_response = get_response
# Parse the primary hostname from WEBSITE_URL
self.primary_host = urlparse(settings.WEBSITE_URL).netloc
self.disable_redirect = settings.DISABLE_REDIRECT
def __call__(self, request):
# Skip redirects in DEBUG mode
if settings.DEBUG:
if settings.DEBUG or self.disable_redirect:
return self.get_response(request)
# Check if the host is different from the primary host

View file

@ -59,6 +59,7 @@ CSRF_TRUSTED_ORIGINS = [f"https://{h}" for h in HTTPS_HOSTS] + [
# Primary website URL
WEBSITE_URL = env.str("WEBSITE_URL", default="https://servala.com")
DISABLE_REDIRECT = env.bool("DISABLE_REDIRECT", default=False)
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
USE_X_FORWARDED_HOST = True