story-kit: merge 71_bug_server_health_endpoint_missing
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
use poem::handler;
|
use poem::handler;
|
||||||
|
use poem_openapi::{Object, OpenApi, Tags, payload::Json};
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
/// Health check endpoint.
|
/// Health check endpoint.
|
||||||
///
|
///
|
||||||
@@ -7,3 +9,40 @@ use poem::handler;
|
|||||||
pub fn health() -> &'static str {
|
pub fn health() -> &'static str {
|
||||||
"ok"
|
"ok"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Tags)]
|
||||||
|
enum HealthTags {
|
||||||
|
Health,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Object)]
|
||||||
|
pub struct HealthStatus {
|
||||||
|
status: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct HealthApi;
|
||||||
|
|
||||||
|
#[OpenApi(tag = "HealthTags::Health")]
|
||||||
|
impl HealthApi {
|
||||||
|
/// Health check endpoint.
|
||||||
|
///
|
||||||
|
/// Returns a JSON status object to confirm the server is running.
|
||||||
|
#[oai(path = "/health", method = "get")]
|
||||||
|
async fn health(&self) -> Json<HealthStatus> {
|
||||||
|
Json(HealthStatus {
|
||||||
|
status: "ok".to_string(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn api_health_returns_ok_status() {
|
||||||
|
let api = HealthApi;
|
||||||
|
let response = api.health().await;
|
||||||
|
assert_eq!(response.0.status, "ok");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use agents::AgentsApi;
|
|||||||
use anthropic::AnthropicApi;
|
use anthropic::AnthropicApi;
|
||||||
use chat::ChatApi;
|
use chat::ChatApi;
|
||||||
use context::AppContext;
|
use context::AppContext;
|
||||||
|
use health::HealthApi;
|
||||||
use io::IoApi;
|
use io::IoApi;
|
||||||
use model::ModelApi;
|
use model::ModelApi;
|
||||||
use poem::EndpointExt;
|
use poem::EndpointExt;
|
||||||
@@ -82,6 +83,7 @@ type ApiTuple = (
|
|||||||
ChatApi,
|
ChatApi,
|
||||||
AgentsApi,
|
AgentsApi,
|
||||||
SettingsApi,
|
SettingsApi,
|
||||||
|
HealthApi,
|
||||||
);
|
);
|
||||||
|
|
||||||
type ApiService = OpenApiService<ApiTuple, ()>;
|
type ApiService = OpenApiService<ApiTuple, ()>;
|
||||||
@@ -96,6 +98,7 @@ pub fn build_openapi_service(ctx: Arc<AppContext>) -> (ApiService, ApiService) {
|
|||||||
ChatApi { ctx: ctx.clone() },
|
ChatApi { ctx: ctx.clone() },
|
||||||
AgentsApi { ctx: ctx.clone() },
|
AgentsApi { ctx: ctx.clone() },
|
||||||
SettingsApi { ctx: ctx.clone() },
|
SettingsApi { ctx: ctx.clone() },
|
||||||
|
HealthApi,
|
||||||
);
|
);
|
||||||
|
|
||||||
let api_service =
|
let api_service =
|
||||||
@@ -109,6 +112,7 @@ pub fn build_openapi_service(ctx: Arc<AppContext>) -> (ApiService, ApiService) {
|
|||||||
ChatApi { ctx: ctx.clone() },
|
ChatApi { ctx: ctx.clone() },
|
||||||
AgentsApi { ctx: ctx.clone() },
|
AgentsApi { ctx: ctx.clone() },
|
||||||
SettingsApi { ctx },
|
SettingsApi { ctx },
|
||||||
|
HealthApi,
|
||||||
);
|
);
|
||||||
|
|
||||||
let docs_service =
|
let docs_service =
|
||||||
|
|||||||
Reference in New Issue
Block a user