Database connection and user registration

This commit is contained in:
Alphonse Paix
2025-08-21 15:38:12 +02:00
parent 1fd1c4eef4
commit ded2a611e2
16 changed files with 3069 additions and 18 deletions

36
src/startup.rs Normal file
View File

@@ -0,0 +1,36 @@
use crate::routes::*;
use axum::{
Router,
extract::MatchedPath,
http::Request,
routing::{get, post},
};
use sqlx::PgPool;
use tokio::net::TcpListener;
use tower_http::trace::TraceLayer;
pub async fn run(listener: TcpListener, connection_pool: PgPool) {
axum::serve(listener, app(connection_pool)).await.unwrap();
}
pub fn app(connection_pool: PgPool) -> Router {
Router::new()
.route("/health_check", get(health_check))
.route("/subscriptions", post(subscribe))
.layer(
TraceLayer::new_for_http().make_span_with(|request: &Request<_>| {
let matched_path = request
.extensions()
.get::<MatchedPath>()
.map(MatchedPath::as_str);
tracing::info_span!(
"http_request",
method = ?request.method(),
matched_path,
some_other_field = tracing::field::Empty,
)
}),
)
.with_state(connection_pool)
}