Skip to content

Commit

Permalink
🎨 Use rocket::launch
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiBardon committed Jan 3, 2024
1 parent 808f2a7 commit a1e36b2
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions src/orangutan/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
let rocket = rocket::build()
#[rocket::launch]
fn rocket() -> _ {
rocket::build()
.mount("/", routes![
clear_cookies,
handle_refresh_token,
Expand All @@ -78,18 +60,23 @@ async fn throwing_main() -> Result<(), Box<dyn std::error::Error>> {
])
.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);
rocket.shutdown().notify();
}
})
}))
.launch()
.await?;

Ok(())
}

fn liftoff() -> Result<(), Error> {
Expand Down

0 comments on commit a1e36b2

Please sign in to comment.