debug: add request-logging middleware + make upload handler sync
- HTTP middleware logs every incoming request (method, path, body size) BEFORE handler runs — catches silent failures at the network/parser layer - Changed upload handler from async to sync so FastAPI runs it in a thread pool, preventing event loop blockage during large file reads
This commit is contained in:
parent
f032c546e1
commit
d8d301a13f
1 changed files with 13 additions and 1 deletions
|
|
@ -40,6 +40,18 @@ from api_client import ApiClient, ApiError, BACKEND_URL
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
app = FastAPI(title="VM Bench — Frontend", version="1.0.0")
|
app = FastAPI(title="VM Bench — Frontend", version="1.0.0")
|
||||||
|
|
||||||
|
# ── Request logging middleware (logs before handler, catches silent failures) ──
|
||||||
|
@app.middleware("http")
|
||||||
|
async def log_requests(request: Request, call_next):
|
||||||
|
cl = request.headers.get("content-length", "?")
|
||||||
|
logger.info("→ %s %s (body %s bytes)", request.method, request.url.path, cl)
|
||||||
|
try:
|
||||||
|
response = await call_next(request)
|
||||||
|
return response
|
||||||
|
except Exception:
|
||||||
|
logger.exception("← %s %s FAILED", request.method, request.url.path)
|
||||||
|
raise
|
||||||
|
|
||||||
BASE = Path(__file__).parent
|
BASE = Path(__file__).parent
|
||||||
app.mount("/static", StaticFiles(directory=str(BASE / "static")), name="static")
|
app.mount("/static", StaticFiles(directory=str(BASE / "static")), name="static")
|
||||||
|
|
||||||
|
|
@ -117,7 +129,7 @@ async def index(request: Request, vmid: Optional[int] = None, source: Optional[s
|
||||||
|
|
||||||
|
|
||||||
@app.post("/session/upload")
|
@app.post("/session/upload")
|
||||||
async def session_upload(
|
def session_upload(
|
||||||
request: Request,
|
request: Request,
|
||||||
vmid: int = Form(...),
|
vmid: int = Form(...),
|
||||||
vm_name: str = Form(""),
|
vm_name: str = Form(""),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue