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