Spaces:
Runtime error

vibra / src /main.py
valent-p's picture
chore: update node_modules dependencies and project configuration files
330c3b5
Raw History Blame Contribute Delete
1.95 kB
from pathlib import Path
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from .config import settings
from .routers import auth, messages, users, websocket
app = FastAPI(
title=settings.APP_NAME,
debug=settings.DEBUG,
version="1.0.0",
)
# CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Restrict this in production if needed
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# API routers
app.include_router(auth.router)
app.include_router(users.router)
app.include_router(messages.router)
app.include_router(websocket.router)
# --------------------------------------------------
# Serve the React frontend (production)
# --------------------------------------------------
frontend_dir = Path(__file__).resolve().parent.parent / "fe" / "dist"
if frontend_dir.exists():
assets_dir = frontend_dir / "assets"
# Serve JS/CSS/images
if assets_dir.exists():
app.mount(
"/assets",
StaticFiles(directory=assets_dir),
name="assets",
)
# Serve favicon if it exists
favicon = frontend_dir / "favicon.ico"
if favicon.exists():
@app.get("/favicon.ico", include_in_schema=False)
async def favicon_file():
return FileResponse(favicon)
# Root
@app.get("/", include_in_schema=False)
async def index():
return FileResponse(frontend_dir / "index.html")
# Every other non-API route returns index.html so React Router handles it.
@app.get("/{full_path:path}", include_in_schema=False)
async def spa(full_path: str):
return FileResponse(frontend_dir / "index.html")
else:
@app.get("/")
async def root():
return {
"status": "online",
"message": "Secure E2EE Chat Engine Server",
}