fix: 调整路由顺序,修复静态文件被JWT拦截的问题
- 将 /static/{tail:.*} 路由移到受保护 scope 之前
- 确保静态文件无需认证即可访问
This commit is contained in:
21
src/handlers/health.rs
Normal file
21
src/handlers/health.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
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": "数据库连接失败"
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user