accept websocket connection on http:.../ws

This commit is contained in:
Andreas Wrede
2026-04-12 06:44:32 -04:00
parent 6559f5462c
commit 7f049a4e26
3 changed files with 93 additions and 168 deletions
+5 -5
View File
@@ -12,6 +12,7 @@ from . import data
from . import notify as notify_mod
from . import settings as settings_mod
from . import users as users_mod
from . import ws as ws_mod
logger = logging.getLogger(__name__)
@@ -242,11 +243,9 @@ async def start(
env = jinja2.Environment(loader=jinja2.FileSystemLoader(templates_dir))
host = config.get("hb_host", "localhost")
extra_scripts = config.get("http_extra_scripts", "")
host = request.host.split(":")[0]
if config.get("wss_port"):
heartbeat_ws_url = f"wss://{host}:{config['wss_port']}/hbd"
else:
heartbeat_ws_url = f"ws://{host}:{config.get('ws_port', 50005)}/hbd"
host = request.host # includes port if non-standard
scheme = "wss" if request.secure else "ws"
heartbeat_ws_url = f"{scheme}://{host}/ws"
tmpl = env.get_template("live.html")
body = tmpl.render(
title="Heartbeat",
@@ -843,6 +842,7 @@ async def start(
web.get("/settings", settings_page),
web.get("/static/{path:.*}", static),
web.get("/favicon.ico", favicon),
web.get("/ws", ws_mod.handler),
]
)