Make dashboard host configurable (LAN reachable via dashboard.host / --host)
This commit is contained in:
+1
-1
@@ -20,5 +20,5 @@
|
|||||||
},
|
},
|
||||||
"log": "data/decisions.jsonl",
|
"log": "data/decisions.jsonl",
|
||||||
"trace": "data/runs.jsonl",
|
"trace": "data/runs.jsonl",
|
||||||
"dashboard": {"port": 8765}
|
"dashboard": {"port": 8765, "host": "0.0.0.0"}
|
||||||
}
|
}
|
||||||
+6
-1
@@ -138,6 +138,11 @@ def main(argv: list[str] | None = None) -> int:
|
|||||||
|
|
||||||
dash_p = sub.add_parser("dashboard", help="run the local browser dashboard")
|
dash_p = sub.add_parser("dashboard", help="run the local browser dashboard")
|
||||||
dash_p.add_argument("--port", type=int, default=int(config.get("dashboard", {}).get("port", 8765)))
|
dash_p.add_argument("--port", type=int, default=int(config.get("dashboard", {}).get("port", 8765)))
|
||||||
|
dash_p.add_argument(
|
||||||
|
"--host",
|
||||||
|
default=str(config.get("dashboard", {}).get("host", "127.0.0.1")),
|
||||||
|
help="bind address (0.0.0.0 to expose on the LAN)",
|
||||||
|
)
|
||||||
dash_p.add_argument(
|
dash_p.add_argument(
|
||||||
"--replay",
|
"--replay",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
@@ -166,7 +171,7 @@ def main(argv: list[str] | None = None) -> int:
|
|||||||
|
|
||||||
if args.replay:
|
if args.replay:
|
||||||
print("replay mode: reading decision log + trace; engine not warmed.")
|
print("replay mode: reading decision log + trace; engine not warmed.")
|
||||||
serve(scheduler, port=args.port)
|
serve(scheduler, port=args.port, host=args.host)
|
||||||
else:
|
else:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -226,10 +226,25 @@ class DashboardHandler(BaseHTTPRequestHandler):
|
|||||||
def serve(scheduler: Scheduler, port: int = 8765, host: str = "127.0.0.1") -> None:
|
def serve(scheduler: Scheduler, port: int = 8765, host: str = "127.0.0.1") -> None:
|
||||||
handler = type("Handler", (DashboardHandler,), {"scheduler": scheduler, "lock": threading.Lock()})
|
handler = type("Handler", (DashboardHandler,), {"scheduler": scheduler, "lock": threading.Lock()})
|
||||||
server = ThreadingHTTPServer((host, port), handler)
|
server = ThreadingHTTPServer((host, port), handler)
|
||||||
print(f"semif dashboard on http://{host}:{port}/ (Ctrl-C to stop)")
|
bound = server.server_address[0]
|
||||||
|
url = f"http://{bound}:{server.server_address[1]}/" if bound != "0.0.0.0" else _lan_url(port)
|
||||||
|
print(f"semif dashboard on {url} (Ctrl-C to stop)")
|
||||||
try:
|
try:
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
server.server_close()
|
server.server_close()
|
||||||
|
|
||||||
|
|
||||||
|
def _lan_url(port: int) -> str:
|
||||||
|
import socket
|
||||||
|
|
||||||
|
try:
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
sock.connect(("8.8.8.8", 80))
|
||||||
|
ip = sock.getsockname()[0]
|
||||||
|
sock.close()
|
||||||
|
except OSError:
|
||||||
|
ip = "127.0.0.1"
|
||||||
|
return f"http://{ip}:{port}/"
|
||||||
Reference in New Issue
Block a user