diff options
Diffstat (limited to 'makima/src/server/mod.rs')
| -rw-r--r-- | makima/src/server/mod.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/makima/src/server/mod.rs b/makima/src/server/mod.rs index a6e0525..c509afa 100644 --- a/makima/src/server/mod.rs +++ b/makima/src/server/mod.rs @@ -6,9 +6,12 @@ pub mod openapi; pub mod state; use axum::{ + http::StatusCode, + response::IntoResponse, routing::get, - Router, + Json, Router, }; +use serde::Serialize; use tower_http::cors::{Any, CorsLayer}; use tower_http::trace::TraceLayer; use utoipa::OpenApi; @@ -18,6 +21,23 @@ use crate::server::handlers::listen; use crate::server::openapi::ApiDoc; use crate::server::state::SharedState; +#[derive(Serialize)] +struct HealthResponse { + status: &'static str, + version: &'static str, +} + +/// Health check endpoint for load balancers and orchestrators. +async fn health_check() -> impl IntoResponse { + ( + StatusCode::OK, + Json(HealthResponse { + status: "healthy", + version: env!("CARGO_PKG_VERSION"), + }), + ) +} + /// Create the axum Router with all routes configured. pub fn make_router(state: SharedState) -> Router { // API v1 routes @@ -29,6 +49,7 @@ pub fn make_router(state: SharedState) -> Router { .url("/api-docs/openapi.json", ApiDoc::openapi()); Router::new() + .route("/api/v1/healthcheck", get(health_check)) .nest("/api/v1", api_v1) .merge(swagger) .layer( |
