kegani-cli 0.1.0

CLI tool for Kegani framework
Documentation
//! Health check routes

use actix_web::{web, HttpResponse};

/// Health check handler
pub async fn health() -> HttpResponse {
    HttpResponse::Ok().json(serde_json::json!({
        "status": "ok",
        "service": env!("CARGO_PKG_NAME")
    }))
}

/// Liveness probe
pub async fn liveness() -> HttpResponse {
    HttpResponse::Ok().json(serde_json::json!({"status": "alive"}))
}

/// Readiness probe
pub async fn readiness() -> HttpResponse {
    HttpResponse::Ok().json(serde_json::json!({"status": "ready"}))
}

/// OpenAPI documentation
pub async fn openapi() -> HttpResponse {
    HttpResponse::Ok()
        .content_type("application/json")
        .body(serde_json::json!({
            "openapi": "3.0.0",
            "info": {
                "title": env!("CARGO_PKG_NAME"),
                "version": env!("CARGO_PKG_VERSION"),
            },
            "paths": {}
        }).to_string())
}

/// Swagger UI page
async fn swagger_ui() -> HttpResponse {
    HttpResponse::Ok()
        .content_type("text/html")
        .body(r#"<!DOCTYPE html>
<html>
<head><title>Swagger UI</title></head>
<body>
<h1>Swagger UI</h1>
<p>Visit <a href="/api-docs/openapi.json">/api-docs/openapi.json</a> for the OpenAPI spec.</p>
</body>
</html>"#)
}

/// ReDoc page
async fn redoc() -> HttpResponse {
    HttpResponse::Ok()
        .content_type("text/html")
        .body(r#"<!DOCTYPE html>
<html>
<head><title>ReDoc</title></head>
<body>
<h1>ReDoc</h1>
<p>Visit <a href="/api-docs/openapi.json">/api-docs/openapi.json</a> for the OpenAPI spec.</p>
</body>
</html>"#)
}

pub fn configure(cfg: &mut web::ServiceConfig) {
    cfg.route("/health", web::get().to(health))
        .route("/health/live", web::get().to(liveness))
        .route("/health/ready", web::get().to(readiness))
        .route("/api-docs/openapi.json", web::get().to(openapi))
        .route("/swagger-ui", web::get().to(swagger_ui))
        .route("/redoc", web::get().to(redoc));
}