Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import asyncio
|
|
| 2 |
import uuid
|
| 3 |
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
|
| 4 |
from fastapi.staticfiles import StaticFiles
|
|
|
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from typing import List, Dict, Any
|
|
@@ -91,6 +92,15 @@ async def handle_api_request(action: str, payload: MockRequest):
|
|
| 91 |
print(f"Erreur dans handle_api_request: {e}")
|
| 92 |
return {"error": f"Une erreur interne est survenue: {str(e)}"}
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
@app.post("/v1/mock")
|
| 95 |
async def mock_endpoint(payload: MockRequest):
|
| 96 |
"""Demande au client une phrase prédéfinie."""
|
|
|
|
| 2 |
import uuid
|
| 3 |
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
|
| 4 |
from fastapi.staticfiles import StaticFiles
|
| 5 |
+
from fastapi.responses import HTMLResponse
|
| 6 |
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
from pydantic import BaseModel
|
| 8 |
from typing import List, Dict, Any
|
|
|
|
| 92 |
print(f"Erreur dans handle_api_request: {e}")
|
| 93 |
return {"error": f"Une erreur interne est survenue: {str(e)}"}
|
| 94 |
|
| 95 |
+
@app.get("/", response_class=HTMLResponse)
|
| 96 |
+
async def root():
|
| 97 |
+
"""Serve the main HTML page."""
|
| 98 |
+
try:
|
| 99 |
+
with open("static/index.html", "r", encoding="utf-8") as f:
|
| 100 |
+
return HTMLResponse(content=f.read())
|
| 101 |
+
except FileNotFoundError:
|
| 102 |
+
raise HTTPException(status_code=404, detail="index.html not found")
|
| 103 |
+
|
| 104 |
@app.post("/v1/mock")
|
| 105 |
async def mock_endpoint(payload: MockRequest):
|
| 106 |
"""Demande au client une phrase prédéfinie."""
|