Download src/main.py from valent-p/vibra: direct link, hf CLI and curl.
- Browser
- Download file 1.95 kB
-
https://huggingface.co/spaces/valent-p/vibra/resolve/main/src/main.py
- Command line
-
hf download hf://spaces/valent-p/vibra/src/main.py
-
curl -L -o main.py https://huggingface.co/spaces/valent-p/vibra/resolve/main/src/main.py
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(): | |
| async def favicon_file(): | |
| return FileResponse(favicon) | |
| # Root | |
| async def index(): | |
| return FileResponse(frontend_dir / "index.html") | |
| # Every other non-API route returns index.html so React Router handles it. | |
| async def spa(full_path: str): | |
| return FileResponse(frontend_dir / "index.html") | |
| else: | |
| async def root(): | |
| return { | |
| "status": "online", | |
| "message": "Secure E2EE Chat Engine Server", | |
| } | |