修复健康检查失败

This commit is contained in:
2025-11-11 00:12:15 +08:00
parent 90b11f4575
commit a05dbfcc47
4 changed files with 14 additions and 2 deletions

View File

@@ -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"`

View File

@@ -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))

View File

@@ -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

View File

@@ -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