fix: 将 /health 路由从根路径移到 /api/v1/system/health
- 原 /health 注册在 FastAPI 根应用上,Nginx 代理 /api/v1/ 前缀无法访问 - 移到 system router 下,外部通过 /api/v1/system/health 访问 - 同步更新 docker-compose.test.yml 和 docker-compose.prod.yml 的 healthcheck 路径
This commit is contained in:
@@ -15,6 +15,22 @@ logger = logging.getLogger(__name__)
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/health", response_model=ApiResponse[dict])
|
||||
async def health_check():
|
||||
"""服务健康检查"""
|
||||
from app.config import get_settings
|
||||
|
||||
settings = get_settings()
|
||||
return success_response(
|
||||
data={
|
||||
"status": "healthy",
|
||||
"version": settings.APP_VERSION,
|
||||
"environment": settings.ENV,
|
||||
},
|
||||
message="服务运行正常",
|
||||
)
|
||||
|
||||
|
||||
@router.get("/version", response_model=ApiResponse[dict])
|
||||
async def system_version():
|
||||
"""获取系统版本信息"""
|
||||
|
||||
@@ -286,20 +286,6 @@ def create_app() -> FastAPI:
|
||||
},
|
||||
)
|
||||
|
||||
# 健康检查
|
||||
@app.get("/health", tags=["System"])
|
||||
async def health_check():
|
||||
"""服务健康检查"""
|
||||
return ApiResponse(
|
||||
code=200,
|
||||
data={
|
||||
"status": "healthy",
|
||||
"version": settings.APP_VERSION,
|
||||
"environment": settings.ENV,
|
||||
},
|
||||
message="服务运行正常",
|
||||
)
|
||||
|
||||
# 根路由
|
||||
@app.get("/", tags=["System"])
|
||||
async def root():
|
||||
|
||||
@@ -44,7 +44,7 @@ services:
|
||||
max-size: "100m"
|
||||
max-file: "5"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://localhost:8000/health')\""]
|
||||
test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://localhost:8000/api/v1/system/health')\""]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
@@ -78,7 +78,7 @@ services:
|
||||
max-size: "100m"
|
||||
max-file: "5"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://localhost:8000/health')\""]
|
||||
test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://localhost:8000/api/v1/system/health')\""]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
Reference in New Issue
Block a user