zero2prod_axum/src/startup.rs

18 lines
515 B
Rust
Raw Normal View History

2023-12-30 22:21:57 +01:00
use axum::routing::IntoMakeService;
use axum::serve::Serve;
use axum::Router;
2024-01-21 22:00:10 +01:00
use sqlx::PgPool;
2023-12-30 22:21:57 +01:00
use tokio::net::TcpListener;
/// API routing
2024-01-21 22:00:10 +01:00
pub fn app(connection: PgPool) -> Router {
2023-12-30 22:21:57 +01:00
Router::new()
.merge(crate::routes::routes_health_check())
2024-01-29 22:18:05 +01:00
.merge(crate::routes::routes_subscriptions(connection.clone()))
2023-12-30 22:21:57 +01:00
}
/// Start the server
2024-01-21 22:00:10 +01:00
pub fn run(listener: TcpListener, connection: PgPool) -> Serve<IntoMakeService<Router>, Router> {
axum::serve(listener, app(connection).into_make_service())
2023-12-30 22:21:57 +01:00
}