Fix relay URL derivation stripping existing port before appending :8765
http://10.10.20.70:3000 was becoming ws://10.10.20.70:3000:8765 instead of ws://10.10.20.70:8765. Extract hostname only via urlparse. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -358,6 +358,23 @@ class Agent:
|
||||
self._stop_event.set()
|
||||
|
||||
|
||||
# ── Helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
def _default_relay_url(server_url: str) -> str:
|
||||
"""Derive the relay WebSocket URL from a server HTTP URL.
|
||||
|
||||
Strips any existing port, swaps the scheme, and appends :8765.
|
||||
e.g. http://10.10.20.70:3000 → ws://10.10.20.70:8765
|
||||
https://remotelink.example.com → wss://remotelink.example.com:8765
|
||||
"""
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
parsed = urlparse(server_url)
|
||||
ws_scheme = "wss" if parsed.scheme == "https" else "ws"
|
||||
# netloc may include a port — strip it, use only the hostname
|
||||
host = parsed.hostname
|
||||
return f"{ws_scheme}://{host}:8765"
|
||||
|
||||
|
||||
# ── Entry point ───────────────────────────────────────────────────────────────
|
||||
|
||||
def setup_logging(verbose: bool):
|
||||
@@ -396,7 +413,7 @@ async def main():
|
||||
sys.exit(1)
|
||||
log.info(f"Enrolling with server {args.server}…")
|
||||
reg = await register(args.server, args.enroll)
|
||||
relay_url = args.relay or args.server.replace("https://", "ws://").replace("http://", "ws://") + ":8765"
|
||||
relay_url = args.relay or _default_relay_url(args.server)
|
||||
config = {
|
||||
"server_url": args.server,
|
||||
"relay_url": relay_url,
|
||||
@@ -414,9 +431,7 @@ async def main():
|
||||
sys.exit(1)
|
||||
|
||||
server_url = config["server_url"]
|
||||
relay_url = config.get("relay_url") or (
|
||||
server_url.replace("https://", "ws://").replace("http://", "ws://") + ":8765"
|
||||
)
|
||||
relay_url = config.get("relay_url") or _default_relay_url(server_url)
|
||||
machine_id = config["machine_id"]
|
||||
access_key = config["access_key"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user