Checking readiness of main app in Controller instead of javascript requests, which break with CORS.
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Controller Tests / controller-tests (push) Waiting to run
Jest Tests / jest-tests (push) Waiting to run

This commit is contained in:
Roland 2026-03-08 16:05:56 -06:00
parent 8c294dad39
commit ef32e8b42d
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
7 changed files with 227 additions and 43 deletions

30
controller/api/ready.py Normal file
View file

@ -0,0 +1,30 @@
"""
Readiness API endpoint for WROLPi Controller.
Allows the controller UI to check if the main API and React app are up
without making cross-origin browser requests.
"""
import asyncio
from fastapi import APIRouter
from controller.api.schemas import ReadyResponse
from controller.lib.readiness import check_api_ready, check_app_ready
router = APIRouter(tags=["readiness"])
@router.get("/api/ready", response_model=ReadyResponse)
async def readiness_check() -> ReadyResponse:
"""
Check if the main WROLPi API and React app are responding.
Performs server-side HTTP requests to avoid CORS and certificate issues
that arise from browser-based cross-origin fetch requests.
"""
api_ready, app_ready = await asyncio.gather(
check_api_ready(),
check_app_ready(),
)
return ReadyResponse(api=api_ready, app=app_ready)

View file

@ -325,3 +325,14 @@ class BranchResponse(BaseModel):
"""Response model for current git branch."""
branch: Optional[str] = Field(description="Current git branch, or null if unavailable")
# ============================================================================
# Readiness
# ============================================================================
class ReadyResponse(BaseModel):
"""Response model for /api/ready endpoint."""
api: bool = Field(description="Whether the main WROLPi API is responding")
app: bool = Field(description="Whether the React app is responding")