Skip to content

Commit

Permalink
remove success message on error
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa committed Aug 5, 2024
1 parent c335d2a commit c76610a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 43 deletions.
40 changes: 2 additions & 38 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::fmt::Write;

use sqlpage::{
app_config::{self, AppConfig},
app_config,
webserver::{self, Database},
AppState,
};
Expand All @@ -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() {
Expand Down
39 changes: 34 additions & 5 deletions src/webserver/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c76610a

Please sign in to comment.