mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 23:16:17 -05:00
Checking readiness of main app in Controller instead of javascript requests, which break with CORS.
This commit is contained in:
parent
8c294dad39
commit
ef32e8b42d
7 changed files with 227 additions and 43 deletions
30
controller/api/ready.py
Normal file
30
controller/api/ready.py
Normal 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)
|
||||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue