Skip to content

Commit

Permalink
Fix detecting https for base url
Browse files Browse the repository at this point in the history
  • Loading branch information
eloravpn committed Dec 20, 2024
1 parent ab8a197 commit 6a63274
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,9 @@ async def custom_config(request: Request):
base_url = config.CUSTOM_BASE_URL

if base_url is None:
# Get domain and port from request
domain = request.headers.get("host", "localhost:8000")
# Detect if request is using HTTPS
protocol = (
"https"
if request.headers.get("x-forwarded-proto") == "https"
else "http"
)
config_data["BASE_URL"] = f"{protocol}://{domain}/api/"
config_data["BASE_URL"] = str(request.base_url) + "api/"
else:
config_data["BASE_URL"] = base_url

return JSONResponse(content=config_data)
except json.JSONDecodeError:
Expand Down

0 comments on commit 6a63274

Please sign in to comment.