Avoid nested hostnames when /dev-sites/ is opened on a site address

This commit is contained in:
sajeyks 2026-09-30 16:03:37 +03:00
commit 748000afd9

View file

@ -95,6 +95,12 @@ class DevSiteSwitcherMiddleware(object):
"""A page listing every configured site as a link, on any host"""
host, _, port = request.get_host().partition(':')
port = ':' + port if port else ''
# opened on a site's own address (e.g. blog.ungleich.ch.localhost):
# drop that site's prefix so links are not nested
for domain in self.domains():
if host.lower().startswith(domain + '.'):
host = host[len(domain) + 1:]
break
if re.match(r'^\d+\.\d+\.\d+\.\d+$', host):
# an IP has no subdomains; sslip.io resolves <anything>.<ip>.sslip.io
base = host + '.sslip.io'