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)