File size: 1,385 Bytes
dc1b015 0681a6b dc1b015 0681a6b dc1b015 0681a6b dc1b015 0681a6b dc1b015 0681a6b dc1b015 0681a6b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | import importlib
import os
import pkgutil
from pathlib import Path
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
# NO request-size cap. Payload bytes are streamed straight to disk by the
# artifact endpoint; JSON bodies are the only in-memory part (uvicorn default).
# Disk is the only size limit — failure surfaces as an error, never a silent truncation.
app = FastAPI(title="Archx Relay v4", version="4.0.0")
_routers = []
projects_dir = Path(__file__).parent / "projects"
if projects_dir.exists():
for module_info in pkgutil.iter_modules([str(projects_dir)]):
if not module_info.ispkg:
continue
name = module_info.name
try:
mod = importlib.import_module(f"projects.{name}.router")
app.include_router(mod.router, prefix=f"/{name}")
_routers.append(name)
except Exception as e:
print(f"Failed to load project '{name}': {e}", flush=True)
@app.get("/health")
def health():
return {"online": "yes", "projects": _routers}
@app.on_event("shutdown")
def _shutdown():
for name in _routers:
try:
mod = importlib.import_module(f"projects.{name}.router")
if hasattr(mod, "store"):
mod.store.stop()
except Exception as e:
print(f"shutdown flush failed for {name}: {e}", flush=True)
|