From 544f3370da3bc72a2b5238c5875f247778d014d4 Mon Sep 17 00:00:00 2001 From: Hunter Casten <41604962+enchantednatures@users.noreply.github.com> Date: Sun, 9 Mar 2025 15:43:27 -0600 Subject: feat(health): add health check endpoint at `/healthz` (#2549) * feat(health): add health check endpoint at `/healthz` * feat(health-check): remove invalid health-check from docker compose --- crates/atuin-server/src/handlers/health.rs | 15 +++++++++++++++ crates/atuin-server/src/handlers/mod.rs | 1 + crates/atuin-server/src/router.rs | 1 + 3 files changed, 17 insertions(+) create mode 100644 crates/atuin-server/src/handlers/health.rs (limited to 'crates') diff --git a/crates/atuin-server/src/handlers/health.rs b/crates/atuin-server/src/handlers/health.rs new file mode 100644 index 00000000..1a3fc4d7 --- /dev/null +++ b/crates/atuin-server/src/handlers/health.rs @@ -0,0 +1,15 @@ +use axum::{http, response::IntoResponse, Json}; + +use serde::Serialize; + +#[derive(Serialize)] +pub struct HealthResponse { + pub status: &'static str, +} + +pub async fn health_check() -> impl IntoResponse { + ( + http::StatusCode::OK, + Json(HealthResponse { status: "healthy" }), + ) +} diff --git a/crates/atuin-server/src/handlers/mod.rs b/crates/atuin-server/src/handlers/mod.rs index ce10f4b7..97132c07 100644 --- a/crates/atuin-server/src/handlers/mod.rs +++ b/crates/atuin-server/src/handlers/mod.rs @@ -4,6 +4,7 @@ use axum::{extract::State, http, response::IntoResponse, Json}; use crate::router::AppState; +pub mod health; pub mod history; pub mod record; pub mod status; diff --git a/crates/atuin-server/src/router.rs b/crates/atuin-server/src/router.rs index df3a2937..d6700b8d 100644 --- a/crates/atuin-server/src/router.rs +++ b/crates/atuin-server/src/router.rs @@ -111,6 +111,7 @@ pub struct AppState { pub fn router(database: DB, settings: Settings) -> Router { let routes = Router::new() .route("/", get(handlers::index)) + .route("/healthz", get(handlers::health::health_check)) .route("/sync/count", get(handlers::history::count)) .route("/sync/history", get(handlers::history::list)) .route("/sync/calendar/:focus", get(handlers::history::calendar)) -- cgit v1.3.1