|
@@ -9,6 +9,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
from pydantic import BaseModel, Field
|
|
from pydantic import BaseModel, Field
|
|
|
from sqlalchemy import text
|
|
from sqlalchemy import text
|
|
|
|
|
+from starlette.exceptions import HTTPException as StarletteHTTPException
|
|
|
|
|
|
|
|
from api.routers.pipeline import router as pipeline_router
|
|
from api.routers.pipeline import router as pipeline_router
|
|
|
from api.services.agent_catalog import (
|
|
from api.services.agent_catalog import (
|
|
@@ -36,6 +37,24 @@ from supply_infra.config import get_infra_settings
|
|
|
from supply_infra.db import dispose_engine, get_session, init_db
|
|
from supply_infra.db import dispose_engine, get_session, init_db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+class SPAStaticFiles(StaticFiles):
|
|
|
|
|
+ """Serve index.html for browser routes handled by Vue Router."""
|
|
|
|
|
+
|
|
|
|
|
+ async def get_response(self, path: str, scope):
|
|
|
|
|
+ try:
|
|
|
|
|
+ return await super().get_response(path, scope)
|
|
|
|
|
+ except StarletteHTTPException as exc:
|
|
|
|
|
+ is_backend_path = (
|
|
|
|
|
+ path == "api"
|
|
|
|
|
+ or path.startswith("api/")
|
|
|
|
|
+ or path == "health"
|
|
|
|
|
+ or path.startswith("health/")
|
|
|
|
|
+ )
|
|
|
|
|
+ if exc.status_code != 404 or is_backend_path or Path(path).suffix:
|
|
|
|
|
+ raise
|
|
|
|
|
+ return await super().get_response("index.html", scope)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@asynccontextmanager
|
|
@asynccontextmanager
|
|
|
async def lifespan(_app: FastAPI):
|
|
async def lifespan(_app: FastAPI):
|
|
|
if get_infra_settings().database_auto_create:
|
|
if get_infra_settings().database_auto_create:
|
|
@@ -309,4 +328,4 @@ def agent_document_injection(
|
|
|
|
|
|
|
|
_web_dist = Path(__file__).resolve().parent.parent / "web" / "dist"
|
|
_web_dist = Path(__file__).resolve().parent.parent / "web" / "dist"
|
|
|
if _web_dist.is_dir():
|
|
if _web_dist.is_dir():
|
|
|
- app.mount("/", StaticFiles(directory=_web_dist, html=True), name="web")
|
|
|
|
|
|
|
+ app.mount("/", SPAStaticFiles(directory=_web_dist, html=True), name="web")
|