Files
asd-backend/src/handlers/health.rs
Milky0217 a819a0db91 fix: 调整路由顺序,修复静态文件被JWT拦截的问题
- 将 /static/{tail:.*} 路由移到受保护 scope 之前
- 确保静态文件无需认证即可访问
2026-04-15 11:51:59 +08:00

22 lines
726 B
Rust

use actix_web::{web, get, HttpResponse, Responder};
use sqlx::postgres::PgPool;
#[get("/health")]
pub async fn health_check(pool: web::Data<PgPool>) -> impl Responder {
// 检查数据库连接
match sqlx::query("SELECT 1").fetch_one(pool.get_ref()).await {
Ok(_) => HttpResponse::Ok().json(serde_json::json!({
"status": "healthy",
"database": "connected"
})),
Err(e) => {
tracing::error!("健康检查失败: {}", e);
HttpResponse::ServiceUnavailable().json(serde_json::json!({
"status": "unhealthy",
"database": "disconnected",
"error": "数据库连接失败"
}))
}
}
}