refactoring main

This commit is contained in:
Zynh Ludwig 2024-08-28 19:10:05 -07:00
parent 772bda8e93
commit d866fa37a6

View file

@ -85,17 +85,7 @@ async fn main() -> io::Result<()> {
.layer(TraceLayer::new_for_http())
.layer(middleware::from_fn(log_source));
// Server creation
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(
listener,
app.into_make_service_with_connect_info::<SocketAddr>(),
)
.await
.unwrap();
tracing::debug!("listening on http://{}/", addr);
serve(app).await;
Ok(())
}
@ -321,3 +311,17 @@ async fn download(
Ok(Redirect::to("/404.html").into_response())
}
async fn serve(app: Router) {
// // Server creation
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(
listener,
app.into_make_service_with_connect_info::<SocketAddr>(),
)
.await
.unwrap();
tracing::debug!("listening on http://{}/", addr);
}