From b8c793f7a45980b442add497b34da2bcc359b778 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Tue, 16 Aug 2022 22:09:16 +0100 Subject: [PATCH] Only log successful startup after server binds to desired port --- src/net/mod.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/net/mod.rs b/src/net/mod.rs index 26cf740e..8d9a7be9 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -62,12 +62,20 @@ pub async fn init() -> Result<(), Error> { info!(target: LOG, "Starting web server on {}", &opt.bind); - info!(target: LOG, "Started web server on {}", &opt.bind); - - if let (Some(crt), Some(key)) = (&opt.crt, &opt.key) { - warp::serve(net).tls().cert_path(crt).key_path(key).run(opt.bind).await + if let (Some(c), Some(k)) = (&opt.crt, &opt.key) { + // Bind the server to the desired port + let (adr, srv) = warp::serve(net).tls().cert_path(c).key_path(k).bind_ephemeral(opt.bind); + // Log the server startup status + info!(target: LOG, "Started web server on {}", &adr); + // Run the server forever + srv.await } else { - warp::serve(net).run(opt.bind).await + // Bind the server to the desired port + let (adr, srv) = warp::serve(net).bind_ephemeral(opt.bind); + // Log the server startup status + info!(target: LOG, "Started web server on {}", &adr); + // Run the server forever + srv.await }; Ok(())