From 75c1d950314fb7fa8b88bae957e6083bb1091001 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 26 Oct 2026 20:34:51 +0100 Subject: add unauthenticated /health and /ready endpoints --- src/api/health.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/api/health.rs (limited to 'src/api/health.rs') diff --git a/src/api/health.rs b/src/api/health.rs new file mode 100644 index 0000000..b1e4523 --- /dev/null +++ b/src/api/health.rs @@ -0,0 +1,20 @@ +//! `GET /health` and `GET /ready`: unauthenticated, for supervisors and load balancers. +//! They say whether the node is up and whether it serves the store, nothing more. + +use axum::{extract::State, http::StatusCode}; + +use crate::state::AppState; + +/// The HTTP API is up. +pub(crate) async fn health() -> &'static str { + "ok\n" +} + +/// The node serves reads and writes: ready, not joining or rejoining. +pub(crate) async fn ready(State(state): State) -> (StatusCode, &'static str) { + if state.is_ready().await { + (StatusCode::OK, "ready\n") + } else { + (StatusCode::SERVICE_UNAVAILABLE, "not ready\n") + } +} -- cgit v1.3.1