mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-20 13:29:37 +02:00
feat: add OverrideHostMiddleware to set HTTP_HOST from PUBLIC_URL environment variable and update nginx configuration
This commit is contained in:
parent
e19781d7ac
commit
a5aa09ed7b
3 changed files with 31 additions and 11 deletions
|
@ -20,4 +20,23 @@ class PrintCookiesMiddleware:
|
|||
def __call__(self, request):
|
||||
print(request.COOKIES)
|
||||
response = self.get_response(request)
|
||||
return response
|
||||
return response
|
||||
|
||||
# middlewares.py
|
||||
|
||||
import os
|
||||
from django.http import HttpRequest
|
||||
|
||||
class OverrideHostMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request: HttpRequest):
|
||||
# Override the host with the PUBLIC_URL environment variable
|
||||
public_url = os.getenv('PUBLIC_URL', None)
|
||||
if public_url:
|
||||
# Split the public URL to extract the host and port (if available)
|
||||
host = public_url.split("//")[-1].split("/")[0]
|
||||
request.META['HTTP_HOST'] = host # Override the HTTP_HOST header
|
||||
response = self.get_response(request)
|
||||
return response
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue