29 lines
848 B
Python
29 lines
848 B
Python
from pathlib import Path
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
from starlette.responses import FileResponse
|
|
|
|
from app.routers import auth, finance, weight, workout
|
|
|
|
app = FastAPI(title="Life Dashboard API")
|
|
|
|
# API routers
|
|
app.include_router(auth.router)
|
|
app.include_router(weight.router)
|
|
app.include_router(workout.router)
|
|
app.include_router(finance.router)
|
|
|
|
# Serve React SPA static files
|
|
STATIC_DIR = Path(__file__).resolve().parent.parent / "static"
|
|
|
|
if STATIC_DIR.exists():
|
|
app.mount("/assets", StaticFiles(directory=STATIC_DIR / "assets"), name="assets")
|
|
|
|
@app.get("/{full_path:path}")
|
|
async def serve_spa(full_path: str):
|
|
file_path = STATIC_DIR / full_path
|
|
if file_path.is_file():
|
|
return FileResponse(file_path)
|
|
return FileResponse(STATIC_DIR / "index.html")
|