|
from fastapi import FastAPI, WebSocket |
|
from fastapi.responses import HTMLResponse |
|
|
|
from fastapi.middleware.cors import CORSMiddleware |
|
|
|
|
|
app = FastAPI() |
|
|
|
origins = [ |
|
"https://orfeohealth.com", |
|
"http://localhost", |
|
"http://localhost:8080", |
|
] |
|
|
|
app.add_middleware( |
|
CORSMiddleware, |
|
allow_origins=origins, |
|
allow_credentials=True, |
|
allow_methods=["*"], |
|
allow_headers=["*"], |
|
) |
|
|
|
|
|
|
|
app.mount("/", StaticFiles(directory="static", html=True), name="static") |
|
|
|
@app.get("/") |
|
def index() -> FileResponse: |
|
return FileResponse(path="/app/static/index.html", media_type="text/html") |
|
|
|
|
|
|
|
@app.websocket("/ws") |
|
async def websocket_endpoint(websocket: WebSocket): |
|
await websocket.accept() |
|
while True: |
|
data = await websocket.receive_text() |
|
await websocket.send_text(f"Message text was: {data}") |