From a1e36b22ff6e6b88505be62f69dc911849b8e1e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bardon?= Date: Tue, 2 Jan 2024 19:44:14 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Use=20`rocket::launch`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/orangutan/src/server.rs | 39 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/src/orangutan/src/server.rs b/src/orangutan/src/server.rs index e09d0a6..0822291 100644 --- a/src/orangutan/src/server.rs +++ b/src/orangutan/src/server.rs @@ -47,27 +47,9 @@ lazy_static! { }; } -#[rocket::main] -async fn main() { - let subscriber = FmtSubscriber::builder() - .with_max_level(Level::TRACE) - .finish(); - - tracing::subscriber::set_global_default(subscriber).expect("Failed to set tracing subscriber."); - - // env_logger::init(); - // env_logger::Builder::new() - // .target(env_logger::Target::Stdout) - // .init(); - - if let Err(err) = throwing_main().await { - error!("Error: {}", err); - exit(1); - } -} - -async fn throwing_main() -> Result<(), Box> { - let rocket = rocket::build() +#[rocket::launch] +fn rocket() -> _ { + rocket::build() .mount("/", routes![ clear_cookies, handle_refresh_token, @@ -78,7 +60,16 @@ async fn throwing_main() -> Result<(), Box> { ]) .register("/", catchers![not_found]) .manage(ObjectReader::new()) - .attach(AdHoc::on_liftoff("Liftoff website generation", |rocket| { + .attach(AdHoc::on_liftoff("Tracing subsciber", |_| { + Box::pin(async move { + let subscriber = FmtSubscriber::builder() + .with_max_level(Level::TRACE) + .finish(); + tracing::subscriber::set_global_default(subscriber) + .expect("Failed to set tracing subscriber."); + }) + })) + .attach(AdHoc::on_liftoff("Website generation", |rocket| { Box::pin(async move { if let Err(err) = liftoff() { error!("Error: {}", err); @@ -86,10 +77,6 @@ async fn throwing_main() -> Result<(), Box> { } }) })) - .launch() - .await?; - - Ok(()) } fn liftoff() -> Result<(), Error> {