fix the async mess
This commit is contained in:
13
app.py
13
app.py
@@ -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>>")
|
||||
|
||||
Reference in New Issue
Block a user