- Update all code references to new name - Rename design document - Update package.json - Update frontend titles and branding Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
77 lines
1.6 KiB
Python
77 lines
1.6 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
import socketio
|
|
from contextlib import asynccontextmanager
|
|
|
|
from app.config import get_settings
|
|
from app.api import admin, game, replay
|
|
from app.sockets.game_events import register_socket_events
|
|
|
|
settings = get_settings()
|
|
|
|
# Socket.IO server
|
|
sio = socketio.AsyncServer(
|
|
async_mode="asgi",
|
|
cors_allowed_origins="*",
|
|
logger=True,
|
|
engineio_logger=True
|
|
)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
# Startup
|
|
print("Starting Trivy server...")
|
|
yield
|
|
# Shutdown
|
|
print("Shutting down Trivy server...")
|
|
|
|
|
|
# FastAPI app
|
|
app = FastAPI(
|
|
title="Trivy API",
|
|
description="API para el juego de trivia multiplayer",
|
|
version="1.0.0",
|
|
lifespan=lifespan
|
|
)
|
|
|
|
# CORS middleware
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(admin.router, prefix="/api/admin", tags=["admin"])
|
|
app.include_router(game.router, prefix="/api/game", tags=["game"])
|
|
app.include_router(replay.router, prefix="/api/replay", tags=["replay"])
|
|
|
|
# Register Socket.IO events
|
|
register_socket_events(sio)
|
|
|
|
# Mount Socket.IO
|
|
socket_app = socketio.ASGIApp(sio, app)
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {
|
|
"message": "Trivy API",
|
|
"version": "1.0.0",
|
|
"status": "running"
|
|
}
|
|
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
return {"status": "healthy"}
|
|
|
|
|
|
# For running with uvicorn directly
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run("app.main:socket_app", host="0.0.0.0", port=8000, reload=True)
|