From c76610a2caf9089394dbaed84c6e47c4aa8ae446 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Mon, 5 Aug 2024 07:12:00 +0200 Subject: [PATCH] remove success message on error --- src/main.rs | 40 ++-------------------------------------- src/webserver/http.rs | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 43 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2b8ed529..5f740e46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,5 @@ -use std::fmt::Write; - use sqlpage::{ - app_config::{self, AppConfig}, + app_config, webserver::{self, Database}, AppState, }; @@ -21,41 +19,7 @@ async fn start() -> anyhow::Result<()> { webserver::database::migrations::apply(&app_config, &db).await?; let state = AppState::init_with_db(&app_config, db).await?; log::debug!("Starting server..."); - let (r, _) = tokio::join!( - webserver::http::run_server(&app_config, state), - log_welcome_message(&app_config) - ); - r -} - -async fn log_welcome_message(config: &AppConfig) { - let address_message = if let Some(unix_socket) = &config.unix_socket { - format!("unix socket {unix_socket:?}") - } else if let Some(domain) = &config.https_domain { - format!("https://{}", domain) - } else { - let listen_on = config.listen_on(); - let mut msg = format!("{listen_on}"); - if listen_on.ip().is_unspecified() { - // let the user know the service is publicly accessible - write!( - msg, - ": accessible from the network, and locally on http://localhost:{}", - listen_on.port() - ) - .unwrap(); - } - msg - }; - - log::info!( - "SQLPage v{} started successfully. - Now listening on {} - You can write your website's code in .sql files in {}", - env!("CARGO_PKG_VERSION"), - address_message, - config.web_root.display() - ); + webserver::http::run_server(&app_config, state).await } fn init_logging() { diff --git a/src/webserver/http.rs b/src/webserver/http.rs index ef59bb52..ed445fc0 100644 --- a/src/webserver/http.rs +++ b/src/webserver/http.rs @@ -597,11 +597,40 @@ pub async fn run_server(config: &AppConfig, state: AppState) -> anyhow::Result<( .map_err(|e| bind_error(e, listen_on))?; } } - server - .run() - .await - .with_context(|| "Unable to start the application")?; - Ok(()) + + let (r, _) = tokio::join!(server.run(), log_welcome_message(&config)); + r.with_context(|| "Unable to start the application") +} + +async fn log_welcome_message(config: &AppConfig) { + let address_message = if let Some(unix_socket) = &config.unix_socket { + format!("unix socket {unix_socket:?}") + } else if let Some(domain) = &config.https_domain { + format!("https://{}", domain) + } else { + use std::fmt::Write; + let listen_on = config.listen_on(); + let mut msg = format!("{listen_on}"); + if listen_on.ip().is_unspecified() { + // let the user know the service is publicly accessible + write!( + msg, + ": accessible from the network, and locally on http://localhost:{}", + listen_on.port() + ) + .unwrap(); + } + msg + }; + + log::info!( + "SQLPage v{} started successfully. + Now listening on {} + You can write your website's code in .sql files in {}", + env!("CARGO_PKG_VERSION"), + address_message, + config.web_root.display() + ); } fn bind_error(e: std::io::Error, listen_on: std::net::SocketAddr) -> anyhow::Error {