-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhealth_endpoints.py
More file actions
48 lines (38 loc) · 1.36 KB
/
Copy pathhealth_endpoints.py
File metadata and controls
48 lines (38 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright (c) 2024 Travis Frisinger
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""Health and status endpoint handlers."""
import logging
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from models.health_responses import (
get_detailed_status,
get_health_status,
get_root_info,
get_status_error,
get_unhealthy_status,
)
logger = logging.getLogger(__name__)
def setup_health_endpoints(app: FastAPI):
"""Setup health and utility endpoints for the WebCat server."""
@app.get("/health")
async def health_check():
"""Health check endpoint for monitoring."""
try:
return get_health_status()
except Exception as e:
logger.error(f"Health check failed: {str(e)}")
return JSONResponse(status_code=500, content=get_unhealthy_status(str(e)))
@app.get("/status")
async def server_status():
"""Detailed server status endpoint."""
try:
return get_detailed_status()
except Exception as e:
logger.error(f"Status check failed: {str(e)}")
return JSONResponse(status_code=500, content=get_status_error(str(e)))
@app.get("/")
async def root():
"""Root endpoint with basic information."""
return get_root_info()