Spaces:
Running
Running
| from __future__ import annotations | |
| import logging | |
| from pathlib import Path | |
| from fastapi import FastAPI, Request | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from app.config import settings | |
| from app.api import decidron | |
| logging.basicConfig(level=logging.INFO) | |
| LOG = logging.getLogger(__name__) | |
| STATIC_DIR = Path(__file__).resolve().parent.parent / "static" | |
| app = FastAPI( | |
| title="Decidron Network Simulator", | |
| version="1.0.0", | |
| ) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=settings.cors_origin_list or ["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| app.include_router(decidron.router, prefix="/api") | |
| async def health(): | |
| return {"status": "ok"} | |
| if STATIC_DIR.is_dir(): | |
| from starlette.staticfiles import StaticFiles # noqa: F401 | |
| from starlette.responses import FileResponse | |
| async def serve_spa(request: Request, full_path: str): | |
| file_path = STATIC_DIR / full_path | |
| if file_path.is_file(): | |
| return FileResponse(file_path) | |
| return FileResponse(STATIC_DIR / "index.html") | |
| LOG.info("Serving frontend from %s", STATIC_DIR) | |
| else: | |
| LOG.info("No static directory found at %s — frontend not served.", STATIC_DIR) | |