Skip to content

Commit

Permalink
wip: Adjust subdomain
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro-Meireles committed Feb 26, 2024
1 parent a944a26 commit 902bd4f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion apip/middlewares/subdomain_mock.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from django.http import Http404
from rest_framework.request import Request
from rest_framework.response import Response
Expand All @@ -10,12 +11,15 @@

def get_request_subdomain(request: Request) -> str:
host: str = request.get_host()

print(host)

host_parts = request.get_host().split(".")

if host.startswith("127.0.0.1"):
return None

if len(host_parts) > 1:
if len(host_parts) > len(settings.SERVICE_HOST.split(".")):
return host_parts[0]

return None
Expand Down
2 changes: 2 additions & 0 deletions apip/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env.bool("DEBUG")

SERVICE_HOST = env.str("SERVICE_HOST", default="localhost")

ALLOWED_HOSTS = env.list("ALLOWED_HOSTS")


Expand Down

0 comments on commit 902bd4f

Please sign in to comment.