From 2524440fe404ba1141079f02f436dab7e1fb84e6 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Thu, 14 May 2026 11:21:58 +0200 Subject: [PATCH] feat(presentation): GET /health endpoint --- crates/presentation/src/handlers/health.rs | 10 ++++++++++ crates/presentation/src/handlers/mod.rs | 1 + crates/presentation/src/routes.rs | 2 ++ 3 files changed, 13 insertions(+) create mode 100644 crates/presentation/src/handlers/health.rs diff --git a/crates/presentation/src/handlers/health.rs b/crates/presentation/src/handlers/health.rs new file mode 100644 index 0000000..0e470a0 --- /dev/null +++ b/crates/presentation/src/handlers/health.rs @@ -0,0 +1,10 @@ +use axum::{extract::State, Json}; +use crate::state::AppState; + +pub async fn health_handler(State(s): State) -> Json { + let db_ok = s.users.list_with_stats().await.is_ok(); + Json(serde_json::json!({ + "status": if db_ok { "ok" } else { "degraded" }, + "db": if db_ok { "connected" } else { "error" }, + })) +} diff --git a/crates/presentation/src/handlers/mod.rs b/crates/presentation/src/handlers/mod.rs index 02c578f..82c8aca 100644 --- a/crates/presentation/src/handlers/mod.rs +++ b/crates/presentation/src/handlers/mod.rs @@ -1,6 +1,7 @@ pub mod api_keys; pub mod auth; pub mod feed; +pub mod health; pub mod notifications; pub mod social; pub mod thoughts; diff --git a/crates/presentation/src/routes.rs b/crates/presentation/src/routes.rs index f8072cb..04511b8 100644 --- a/crates/presentation/src/routes.rs +++ b/crates/presentation/src/routes.rs @@ -16,6 +16,8 @@ use crate::{handlers::*, state::AppState}; pub fn router(fed_config: &ApFederationConfig) -> Router { let api_routes = Router::new() + // health + .route("/health", get(health::health_handler)) // auth .route("/auth/register", post(auth::post_register)) .route("/auth/login", post(auth::post_login))