feat(server): implement websocket chat backend

This commit is contained in:
2026-06-16 14:17:46 +03:30
parent de4e478d04
commit 5d8eab071e
5 changed files with 197 additions and 0 deletions

36
app/main.py Normal file
View File

@@ -0,0 +1,36 @@
from pathlib import Path
from fastapi import FastAPI
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from app.websocket.chat import router as chat_router
from app.websocket.manager import manager
BASE_DIR = Path(__file__).resolve().parent
STATIC_DIR = BASE_DIR / "static"
app = FastAPI(title="Simple WebSocket Chatroom")
# WebSocket route: ws://localhost:8000/ws/{room_id}/{client_id}
app.include_router(chat_router)
# Frontend files
app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
@app.get("/")
async def home():
"""Serve the chatroom GUI."""
return FileResponse(STATIC_DIR / "index.html")
@app.get("/api/rooms")
async def rooms():
"""Small helper endpoint for the GUI/debugging."""
return manager.rooms_overview()
@app.get("/health")
async def health():
return {"status": "ok", "app": "Simple WebSocket Chatroom"}