Make devserver backend health check endpoint configurable, preserved in upgrades and optional.

This commit is contained in:
2026-03-07 23:55:10 +00:00
parent aac27da67c
commit 1aaf040db7
3 changed files with 60 additions and 5 deletions
+2 -1
View File
@@ -22,6 +22,7 @@ from devutil import ( # type: ignore
DEFAULT_VITE_PORT = TEMPLATE_VITE_PORT
DEFAULT_DEV_PORT = TEMPLATE_DEV_PORT
HEALTH = TEMPLATE_HEALTH
async def run_devserver(
@@ -45,7 +46,7 @@ async def run_devserver(
npm_i = await pg.spawn(*npm_install, cwd=front)
await check_ports_free(viteurl, backurl)
await pg.spawn(*MODULE_NAME, *(extra_args or []))
await pg.wait(npm_i, ready(backurl, path="/api/health?from=devserver.py"))
await pg.wait(npm_i, ready(backurl, path=HEALTH))
await pg.spawn(*vite, cwd=front)
+5 -4
View File
@@ -111,18 +111,19 @@ async def check_ports_free(*urls: str) -> None:
await asyncio.gather(*[check(client, url) for url in urls])
async def ready(url: str, path: str = "") -> None:
async def ready(url: str, path: str = "", max_attempts=50) -> None:
"""Wait for the server to be ready by polling an endpoint.
Use empty path to disable the check and make this return immediately.
Raises SystemExit(1) if server doesn't start in time.
"""
max_attempts = 50
full_url = f"{url}{path}"
if not path:
return
async with httpx.AsyncClient() as client:
for attempt in range(max_attempts):
try:
await client.get(full_url, timeout=1.0)
await client.get(f"{url}{path}", timeout=1.0)
logger.info("✓ Backend ready!")
return
except httpx.RequestError: