chore: gracefully handle favicon issue
This commit is contained in:
parent
501cebe342
commit
86567f93e8
1 changed files with 29 additions and 15 deletions
|
|
@ -21,13 +21,14 @@ os.makedirs(staticFolder, exist_ok=True)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
router = APIRouter(
|
router = APIRouter(
|
||||||
prefix="",
|
prefix="", tags=["Administration"], responses={404: {"description": "Not found"}}
|
||||||
tags=["Administration"],
|
|
||||||
responses={404: {"description": "Not found"}}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Mount static files
|
# Mount static files
|
||||||
router.mount("/static", StaticFiles(directory=str(staticFolder), html=True), name="static")
|
router.mount(
|
||||||
|
"/static", StaticFiles(directory=str(staticFolder), html=True), name="static"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/")
|
@router.get("/")
|
||||||
@limiter.limit("30/minute")
|
@limiter.limit("30/minute")
|
||||||
|
|
@ -36,22 +37,29 @@ async def root(request: Request) -> Dict[str, str]:
|
||||||
# Validate required configuration values
|
# Validate required configuration values
|
||||||
allowedOrigins = APP_CONFIG.get("APP_ALLOWED_ORIGINS")
|
allowedOrigins = APP_CONFIG.get("APP_ALLOWED_ORIGINS")
|
||||||
if not allowedOrigins:
|
if not allowedOrigins:
|
||||||
raise HTTPException(status_code=500, detail="APP_ALLOWED_ORIGINS configuration is required")
|
raise HTTPException(
|
||||||
|
status_code=500, detail="APP_ALLOWED_ORIGINS configuration is required"
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"status": "online",
|
"status": "online",
|
||||||
"message": "Data Platform API is active",
|
"message": "Data Platform API is active",
|
||||||
"allowedOrigins": f"Allowed origins are {allowedOrigins}"
|
"allowedOrigins": f"Allowed origins are {allowedOrigins}",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/environment")
|
@router.get("/api/environment")
|
||||||
@limiter.limit("30/minute")
|
@limiter.limit("30/minute")
|
||||||
async def get_environment(request: Request, currentUser: Dict[str, Any] = Depends(getCurrentUser)) -> Dict[str, str]:
|
async def get_environment(
|
||||||
|
request: Request, currentUser: Dict[str, Any] = Depends(getCurrentUser)
|
||||||
|
) -> Dict[str, str]:
|
||||||
"""Get environment configuration for frontend"""
|
"""Get environment configuration for frontend"""
|
||||||
# Validate required configuration values
|
# Validate required configuration values
|
||||||
apiBaseUrl = APP_CONFIG.get("APP_API_URL")
|
apiBaseUrl = APP_CONFIG.get("APP_API_URL")
|
||||||
if not apiBaseUrl:
|
if not apiBaseUrl:
|
||||||
raise HTTPException(status_code=500, detail="APP_API_URL configuration is required")
|
raise HTTPException(
|
||||||
|
status_code=500, detail="APP_API_URL configuration is required"
|
||||||
|
)
|
||||||
|
|
||||||
environment = APP_CONFIG.get("APP_ENV")
|
environment = APP_CONFIG.get("APP_ENV")
|
||||||
if not environment:
|
if not environment:
|
||||||
|
|
@ -59,7 +67,9 @@ async def get_environment(request: Request, currentUser: Dict[str, Any] = Depend
|
||||||
|
|
||||||
instanceLabel = APP_CONFIG.get("APP_ENV_LABEL")
|
instanceLabel = APP_CONFIG.get("APP_ENV_LABEL")
|
||||||
if not instanceLabel:
|
if not instanceLabel:
|
||||||
raise HTTPException(status_code=500, detail="APP_ENV_LABEL configuration is required")
|
raise HTTPException(
|
||||||
|
status_code=500, detail="APP_ENV_LABEL configuration is required"
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"apiBaseUrl": apiBaseUrl,
|
"apiBaseUrl": apiBaseUrl,
|
||||||
|
|
@ -68,13 +78,17 @@ async def get_environment(request: Request, currentUser: Dict[str, Any] = Depend
|
||||||
# Add other environment variables the frontend might need
|
# Add other environment variables the frontend might need
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.options("/{fullPath:path}")
|
@router.options("/{fullPath:path}")
|
||||||
@limiter.limit("60/minute")
|
@limiter.limit("60/minute")
|
||||||
async def options_route(request: Request, fullPath: str) -> Response:
|
async def options_route(request: Request, fullPath: str) -> Response:
|
||||||
return Response(status_code=200)
|
return Response(status_code=200)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/favicon.ico")
|
@router.get("/favicon.ico")
|
||||||
@limiter.limit("30/minute")
|
@limiter.limit("30/minute")
|
||||||
async def favicon(request: Request) -> FileResponse:
|
async def favicon(request: Request) -> FileResponse:
|
||||||
return FileResponse(str(staticFolder / "favicon.ico"), media_type="image/x-icon")
|
favicon_path = staticFolder / "favicon.ico"
|
||||||
|
if not favicon_path.exists():
|
||||||
|
raise HTTPException(status_code=404, detail="Favicon not found")
|
||||||
|
return FileResponse(str(favicon_path), media_type="image/x-icon")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue