use axum::Json;
use axum::extract::State;
use axum::http::StatusCode;
use serde::Serialize;
use crate::server::AppState;
#[derive(Serialize)]
pub struct HealthResponse {
pub status: &'static str,
pub service: &'static str,
pub version: &'static str,
}
pub async fn health(State(state): State<AppState>) -> (StatusCode, Json<HealthResponse>) {
let ok = did_hosting_common::server::health::own_did_served_locally(
&state.dids_ks,
state.config.server_did.as_deref(),
)
.await;
let status = if ok {
StatusCode::OK
} else {
StatusCode::SERVICE_UNAVAILABLE
};
(
status,
Json(HealthResponse {
status: if ok { "ok" } else { "degraded" },
service: "did-hosting-control",
version: env!("CARGO_PKG_VERSION"),
}),
)
}