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__)
|
||||
|
||||
router = APIRouter(
|
||||
prefix="",
|
||||
tags=["Administration"],
|
||||
responses={404: {"description": "Not found"}}
|
||||
prefix="", tags=["Administration"], responses={404: {"description": "Not found"}}
|
||||
)
|
||||
|
||||
# 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("/")
|
||||
@limiter.limit("30/minute")
|
||||
|
|
@ -36,31 +37,40 @@ async def root(request: Request) -> Dict[str, str]:
|
|||
# Validate required configuration values
|
||||
allowedOrigins = APP_CONFIG.get("APP_ALLOWED_ORIGINS")
|
||||
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 {
|
||||
"status": "online",
|
||||
"message": "Data Platform API is active",
|
||||
"allowedOrigins": f"Allowed origins are {allowedOrigins}"
|
||||
"allowedOrigins": f"Allowed origins are {allowedOrigins}",
|
||||
}
|
||||
|
||||
|
||||
@router.get("/api/environment")
|
||||
@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"""
|
||||
# Validate required configuration values
|
||||
apiBaseUrl = APP_CONFIG.get("APP_API_URL")
|
||||
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")
|
||||
if not environment:
|
||||
raise HTTPException(status_code=500, detail="APP_ENV configuration is required")
|
||||
|
||||
|
||||
instanceLabel = APP_CONFIG.get("APP_ENV_LABEL")
|
||||
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 {
|
||||
"apiBaseUrl": apiBaseUrl,
|
||||
"environment": environment,
|
||||
|
|
@ -68,13 +78,17 @@ async def get_environment(request: Request, currentUser: Dict[str, Any] = Depend
|
|||
# Add other environment variables the frontend might need
|
||||
}
|
||||
|
||||
|
||||
@router.options("/{fullPath:path}")
|
||||
@limiter.limit("60/minute")
|
||||
async def options_route(request: Request, fullPath: str) -> Response:
|
||||
return Response(status_code=200)
|
||||
|
||||
|
||||
@router.get("/favicon.ico")
|
||||
@limiter.limit("30/minute")
|
||||
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