Trae Bot commited on
Commit
8336f26
·
1 Parent(s): 98b1b21

Build and serve frontend UI at root path

Browse files
Files changed (2) hide show
  1. Dockerfile +3 -0
  2. service/app.py +9 -3
Dockerfile CHANGED
@@ -22,6 +22,9 @@ RUN npm install
22
 
23
  COPY . .
24
 
 
 
 
25
  ENV PYTHONPATH=/app
26
  ENV PYTHONUNBUFFERED=1
27
 
 
22
 
23
  COPY . .
24
 
25
+ # Build frontend
26
+ RUN cd frontend && npm install && npm run build
27
+
28
  ENV PYTHONPATH=/app
29
  ENV PYTHONUNBUFFERED=1
30
 
service/app.py CHANGED
@@ -8,6 +8,7 @@ from fastapi.exceptions import RequestValidationError
8
  from fastapi.responses import JSONResponse, RedirectResponse
9
  from starlette.exceptions import HTTPException as StarletteHTTPException
10
  from fastapi.middleware.cors import CORSMiddleware
 
11
 
12
  _pkg_root = Path(__file__).resolve().parents[1]
13
  if str(_pkg_root) not in sys.path:
@@ -73,9 +74,14 @@ def create_app() -> FastAPI:
73
  if config.enable_legacy_routes:
74
  app.include_router(base_router)
75
 
76
- @app.get("/", include_in_schema=False)
77
- def root_redirect():
78
- return RedirectResponse(url="/docs")
 
 
 
 
 
79
 
80
  @app.exception_handler(ApiException)
81
  async def _handle_api_exception(_: Request, exc: ApiException) -> JSONResponse:
 
8
  from fastapi.responses import JSONResponse, RedirectResponse
9
  from starlette.exceptions import HTTPException as StarletteHTTPException
10
  from fastapi.middleware.cors import CORSMiddleware
11
+ from fastapi.staticfiles import StaticFiles
12
 
13
  _pkg_root = Path(__file__).resolve().parents[1]
14
  if str(_pkg_root) not in sys.path:
 
74
  if config.enable_legacy_routes:
75
  app.include_router(base_router)
76
 
77
+ # Serve built frontend static files
78
+ frontend_dist = _pkg_root / "frontend" / "dist"
79
+ if frontend_dist.exists() and frontend_dist.is_dir():
80
+ app.mount("/", StaticFiles(directory=str(frontend_dist), html=True), name="frontend")
81
+ else:
82
+ @app.get("/", include_in_schema=False)
83
+ def root_redirect():
84
+ return RedirectResponse(url="/docs")
85
 
86
  @app.exception_handler(ApiException)
87
  async def _handle_api_exception(_: Request, exc: ApiException) -> JSONResponse: