mirror of
https://github.com/complexcaresolutions/dak.c2s.git
synced 2026-03-17 16:03:41 +00:00
feat: serve frontend SPA from FastAPI backend
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
1edf5835be
commit
4a3648a018
1 changed files with 22 additions and 1 deletions
|
|
@ -1,6 +1,10 @@
|
|||
# backend/app/main.py
|
||||
from fastapi import FastAPI
|
||||
import os
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from app.api.admin import router as admin_router
|
||||
from app.api.auth import router as auth_router
|
||||
|
|
@ -36,3 +40,20 @@ app.include_router(reports_router, prefix="/api/reports", tags=["reports"])
|
|||
@app.get("/api/health")
|
||||
def health_check():
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
# --- Serve frontend SPA ---
|
||||
_frontend_dist = os.path.join(
|
||||
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
|
||||
"frontend", "dist",
|
||||
)
|
||||
|
||||
if os.path.isdir(_frontend_dist):
|
||||
app.mount("/assets", StaticFiles(directory=os.path.join(_frontend_dist, "assets")), name="static")
|
||||
|
||||
@app.get("/{full_path:path}")
|
||||
async def serve_spa(request: Request, full_path: str):
|
||||
file_path = os.path.join(_frontend_dist, full_path)
|
||||
if full_path and os.path.isfile(file_path):
|
||||
return FileResponse(file_path)
|
||||
return FileResponse(os.path.join(_frontend_dist, "index.html"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue