diff --git a/src/routes/api.rs b/src/routes/api.rs index 5d24fe8..812e2f9 100644 --- a/src/routes/api.rs +++ b/src/routes/api.rs @@ -29,6 +29,8 @@ pub fn layer() -> axum::Router> { .layer(ValidateRequestHeaderLayer::bearer( &bearer_token.unwrap_or_else(|_| DEFAULT_API_KEY.to_string()), )) + // No authentication required for health check + .route("/health-check", get(health_check)) } #[typeshare] @@ -148,3 +150,18 @@ async fn delete_url( StatusCode::NO_CONTENT.into_response() } + +async fn health_check(State(state): State>) -> impl IntoResponse { + // Check database connection + let conn = state.db.clone(); + let rows = conn.query("SELECT 1", ()).await; + + match rows { + Err(_) => ( + StatusCode::INTERNAL_SERVER_ERROR, + "Database connection failed", + ) + .into_response(), + Ok(_) => (StatusCode::OK, "OK").into_response(), + } +}