From b3701cd2e929710c9f4674a26a94479f24e6acaa Mon Sep 17 00:00:00 2001 From: Hugh Kaznowski Date: Sat, 5 Sep 2026 15:06:46 +0100 Subject: [PATCH] Default --port to 0 for OS-assigned ephemeral port (ticket 019) Reads back the actual bound port via listener.local_addr() since binding to 0 means the requested and real ports differ. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01XFUNZwCvz3kcod3352ZR2o --- src/main.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4fd644b..8650b71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,8 +25,9 @@ use settings::Settings; /// Observability dashboard from terminal output. #[derive(Parser, Debug)] struct Args { - /// Port to serve the API and webapp on. - #[arg(long, default_value_t = 8420)] + /// Port to serve the API and webapp on. Defaults to 0, letting the OS assign + /// an ephemeral free port. + #[arg(long, default_value_t = 0)] port: u16, /// Directory containing the built webapp (index.html + assets). @@ -91,10 +92,14 @@ async fn main() { let listener = TcpListener::bind(("0.0.0.0", args.port)) .await .expect("failed to bind listener"); + let bound_port = listener + .local_addr() + .expect("failed to read back bound address") + .port(); eprintln!( "ottyl serving on http://localhost:{} (reading logs from stdin)", - args.port + bound_port ); axum::serve(listener, app)