feat(discord-bridge): dashboard publicat in tailnet prin tailscale serve
https://claude-agent.tailf7372d.ts.net/punte — acelasi tipar ca /echo de pe moltbot: procesul ramane legat de 127.0.0.1, tailscaled il proxeaza si pune HTTPS. Montarea sub prefix a cerut doua schimbari: - toate URL-urile din pagini sunt acum relative, fiindca --set-path TAIE prefixul inainte de a proxa (serverul vede /api/status, browserul cere /punte/api/status). DASHBOARD_PREFIX ramane necesar doar pentru redirectul de login, si e acceptat si intact pe intrare, ca sa mearga si curl direct pe localhost. - adresa fara slash final (/punte) primeste 301 catre /punte/: altfel URL-urile relative s-ar rezolva la radacina hostului, unde proxy-ul nu trimite nimic incoace, si panoul ar arata gol fara nicio eroare vizibila. ops/install.sh configureaza serve-ul daca sudo permite; altfel spune comanda. Sase teste noi pentru montarea sub prefix (31 in total pe dashboard). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B29CApsP1JkSdjYaGaHpE7
This commit is contained in:
@@ -60,6 +60,27 @@ def infra_log() -> Path:
|
||||
COOKIE_NAME = "dashboard"
|
||||
COOKIE_MAX_AGE = 60 * 60 * 24 * 30
|
||||
|
||||
|
||||
def mount_prefix() -> str:
|
||||
"""Prefixul sub care e montat panoul (`DASHBOARD_PREFIX`, ex. `/punte`).
|
||||
|
||||
`tailscale serve --set-path /punte` TAIE prefixul inainte de a proxa, deci in
|
||||
mod normal aici ajunge `/api/status`. Prefixul e acceptat totusi si intact,
|
||||
pentru cazul unui proxy care nu taie si pentru `curl` direct pe localhost.
|
||||
Paginile nu depind de el: toate URL-urile din HTML sunt relative.
|
||||
"""
|
||||
pfx = (config.get("DASHBOARD_PREFIX") or "").strip().rstrip("/")
|
||||
if pfx and not pfx.startswith("/"):
|
||||
pfx = "/" + pfx
|
||||
return pfx
|
||||
|
||||
|
||||
def strip_prefix(path: str) -> str:
|
||||
pfx = mount_prefix()
|
||||
if pfx and (path == pfx or path.startswith(pfx + "/")):
|
||||
return path[len(pfx):] or "/"
|
||||
return path
|
||||
|
||||
_TOKEN: str | None = None
|
||||
|
||||
|
||||
@@ -378,19 +399,34 @@ class Handler(SimpleHTTPRequestHandler):
|
||||
|
||||
# --- GET -----------------------------------------------------------
|
||||
def do_GET(self):
|
||||
path = urlparse(self.path).path
|
||||
raw = urlparse(self.path).path
|
||||
path = strip_prefix(raw)
|
||||
if path == "/" and not raw.endswith("/"):
|
||||
# `/punte` fara slash final: URL-urile relative din pagina s-ar
|
||||
# rezolva la radacina hostului (`/api/status`), unde proxy-ul nu mai
|
||||
# trimite nimic incoace. Fortam forma cu slash.
|
||||
self.send_response(301)
|
||||
self.send_header("Location", raw + "/")
|
||||
self.send_header("Content-Length", "0")
|
||||
self.end_headers()
|
||||
return
|
||||
if path.startswith("/api/"):
|
||||
if not self.authed():
|
||||
return self.deny()
|
||||
return self.route_get(path)
|
||||
if path in ("/", "/index.html") and not self.authed():
|
||||
# Prefixul reintra AICI in mod deliberat. Un "/login.html" absolut ar
|
||||
# arunca browserul in radacina hostului (alt serviciu), iar un
|
||||
# "login.html" relativ se rezolva gresit cand adresa vine fara slash
|
||||
# final (`/punte` -> `/login.html`). Cu prefixul reatasat, ambele
|
||||
# forme ajung unde trebuie, si direct pe localhost la fel: calea de
|
||||
# intrare e curatata oricum de `strip_prefix`.
|
||||
self.send_response(302)
|
||||
self.send_header("Location", "/login.html")
|
||||
self.send_header("Location", mount_prefix() + "/login.html")
|
||||
self.send_header("Content-Length", "0")
|
||||
self.end_headers()
|
||||
return
|
||||
if path == "/":
|
||||
self.path = "/index.html"
|
||||
self.path = "/index.html" if path == "/" else path
|
||||
return super().do_GET()
|
||||
|
||||
def route_get(self, path: str):
|
||||
@@ -428,7 +464,7 @@ class Handler(SimpleHTTPRequestHandler):
|
||||
|
||||
# --- POST ----------------------------------------------------------
|
||||
def do_POST(self):
|
||||
path = urlparse(self.path).path
|
||||
path = strip_prefix(urlparse(self.path).path)
|
||||
if path == "/api/auth/login":
|
||||
return self.handle_login()
|
||||
if path == "/api/auth/logout":
|
||||
|
||||
Reference in New Issue
Block a user