From a05dbfcc479f0e484be19303b27f081af8a0d8c8 Mon Sep 17 00:00:00 2001 From: nanako <469449812@qq.com> Date: Tue, 11 Nov 2025 00:12:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=81=A5=E5=BA=B7=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/api/handlers.go | 8 ++++++++ backend/main.go | 4 ++++ docker-compose.cn.yml | 2 +- docker-compose.yml | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/backend/api/handlers.go b/backend/api/handlers.go index d661583..ab99a4e 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -18,6 +18,14 @@ type APIHandler struct { DB *gorm.DB } +// HealthCheckHandler 健康检查端点(无需认证) +func (h *APIHandler) HealthCheckHandler(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{ + "status": "ok", + "timestamp": time.Now().Unix(), + }) +} + // ModelListResponse 符合OpenAI /v1/models API响应格式 type ModelListResponse struct { Object string `json:"object"` diff --git a/backend/main.go b/backend/main.go index 0859d56..03fb760 100644 --- a/backend/main.go +++ b/backend/main.go @@ -39,6 +39,10 @@ func main() { DB: database, } + // 添加健康检查端点(无需认证) + router.GET("/health", handler.HealthCheckHandler) + router.GET("/healthz", handler.HealthCheckHandler) + // 创建根组 root_ := router.Group("/") root_.Use(middleware.AuthMiddleware(database)) diff --git a/docker-compose.cn.yml b/docker-compose.cn.yml index 79c34bd..06407d4 100644 --- a/docker-compose.cn.yml +++ b/docker-compose.cn.yml @@ -21,7 +21,7 @@ services: networks: - ai-router-network healthcheck: - test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/api/providers"] + test: ["CMD", "wget", "--no-verbose", "--tries=1", "-O", "/dev/null", "http://localhost:8080/health"] interval: 30s timeout: 10s retries: 3 diff --git a/docker-compose.yml b/docker-compose.yml index cab9fa0..e242e02 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,7 +17,7 @@ services: networks: - ai-router-network healthcheck: - test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/api/providers"] + test: ["CMD", "wget", "--no-verbose", "--tries=1", "-O", "/dev/null", "http://localhost:8080/health"] interval: 30s timeout: 10s retries: 3