feat: implement native subdomain routing (*.hub.yesminedor.tn) for seamless absolute assets resolution across all universes

This commit is contained in:
bolbol
2026-08-20 09:03:30 +01:00
parent b6ce9788f3
commit e074015b72
3 changed files with 86 additions and 20 deletions
+11 -5
View File
@@ -40,7 +40,7 @@ async def close_http_client():
def rewrite_cookie_path(cookie_header: str, universe_id: str) -> str:
"""
Rewrites the Path attribute of a Set-Cookie header to /u/{universe_id}/
to strictly isolate session cookies between Hermes universes.
when using path-based proxying.
"""
target_path = f"/u/{universe_id}/"
if re.search(r'(?i)\bpath=[^;]*', cookie_header):
@@ -83,9 +83,15 @@ async def proxy_request(
for key, value in request.headers.items():
if key.lower() not in HOP_BY_HOP_HEADERS and key.lower() != "host":
req_headers[key] = value
# Forward original host header info
req_headers["x-forwarded-host"] = request.headers.get("host", "")
req_headers["x-forwarded-proto"] = request.url.scheme or "http"
body = await request.body()
is_path_proxied = universe_id and request.url.path.startswith(f"/u/{universe_id}")
try:
upstream_req = client.build_request(
method=request.method,
@@ -107,12 +113,12 @@ async def proxy_request(
if k_str in HOP_BY_HOP_HEADERS:
continue
if k_str == "set-cookie" and universe_id:
# Cloisonnement strict des cookies de session par univers
if k_str == "set-cookie" and is_path_proxied:
# Path-based proxying: rewrite cookie path
v_str = rewrite_cookie_path(v_str, universe_id)
raw_headers.append((b"set-cookie", v_str.encode("latin-1")))
elif k_str == "location" and universe_id:
# Réécriture de la redirection si le backend renvoie vers la racine /
elif k_str == "location" and is_path_proxied:
# Path-based proxying: rewrite location redirect
if v_str.startswith("/") and not v_str.startswith(f"/u/{universe_id}"):
v_str = f"/u/{universe_id}{v_str}"
raw_headers.append((b"location", v_str.encode("latin-1")))