fix the async mess

This commit is contained in:
Matteo Rosati
2026-01-22 09:44:17 +01:00
parent 31ee3fed8c
commit 1ed452f1d9
2 changed files with 19 additions and 11 deletions

13
app.py
View File

@@ -8,7 +8,14 @@ import os
import logging
from typing import Annotated
from fastapi import FastAPI, Request, WebSocket, Depends, HTTPException, status
from fastapi import (
FastAPI,
Request,
WebSocket,
Depends,
HTTPException,
status,
)
from fastapi.security import HTTPBasic, HTTPBasicCredentials
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
@@ -67,7 +74,7 @@ templates = Jinja2Templates(directory=os.path.join(STATIC_DIR, TEMPLATES_DIR))
@app.get("/")
async def home(request: Request, username: Annotated[str, Depends(verify_credentials)]):
def home(request: Request, username: Annotated[str, Depends(verify_credentials)]):
"""Render the main index page.
Args:
@@ -91,7 +98,7 @@ async def websocket_endpoint(websocket: WebSocket):
while True:
data = await websocket.receive_text()
for chunk in generate(data):
async for chunk in generate(data):
await websocket.send_text(chunk)
await websocket.send_text("<<END>>")