mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-03-14 20:32:51 +00:00

If SITE_ROOT contains a subpath (e.g., "http://example.org/healthchecks"), settings.py now adjusts FORCE_SCRIPT_NAME and STATIC_URL. Also, hc.lib.urls.absolute_reverse() now recognizes subpath in SITE_ROOT, and makes sure it does not show up twice in the generated URLs. cc: #1091
19 lines
592 B
Python
19 lines
592 B
Python
from collections.abc import Callable, Sequence
|
|
from typing import Any
|
|
from urllib.parse import urlparse
|
|
|
|
from django.conf import settings
|
|
from django.http.response import HttpResponse
|
|
from django.urls import reverse
|
|
|
|
|
|
def absolute_url(path: str) -> str:
|
|
subpath = urlparse(settings.SITE_ROOT).path
|
|
return settings.SITE_ROOT.removesuffix(subpath) + path
|
|
|
|
|
|
def absolute_reverse(
|
|
viewname: str | Callable[..., HttpResponse], args: Sequence[Any] | None = None
|
|
) -> str:
|
|
"""Generate absolute URL (starting with http[s]://)."""
|
|
return absolute_url(reverse(viewname, args=args))
|