mirror of
https://github.com/google-gemini/gemini-fullstack-langgraph-quickstart.git
synced 2025-08-08 00:41:45 +03:00
Merge pull request #78 from google-gemini/fix-react-serving
update react serving part
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
# mypy: disable - error - code = "no-untyped-def,misc"
|
||||
import pathlib
|
||||
from fastapi import FastAPI, Request, Response
|
||||
from fastapi import FastAPI, Response
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
import fastapi.exceptions
|
||||
|
||||
# Define the FastAPI app
|
||||
app = FastAPI()
|
||||
@@ -18,7 +17,6 @@ def create_frontend_router(build_dir="../frontend/dist"):
|
||||
A Starlette application serving the frontend.
|
||||
"""
|
||||
build_path = pathlib.Path(__file__).parent.parent.parent / build_dir
|
||||
static_files_path = build_path / "assets" # Vite uses 'assets' subdir
|
||||
|
||||
if not build_path.is_dir() or not (build_path / "index.html").is_file():
|
||||
print(
|
||||
@@ -36,21 +34,7 @@ def create_frontend_router(build_dir="../frontend/dist"):
|
||||
|
||||
return Route("/{path:path}", endpoint=dummy_frontend)
|
||||
|
||||
build_dir = pathlib.Path(build_dir)
|
||||
|
||||
react = FastAPI(openapi_url="")
|
||||
react.mount(
|
||||
"/assets", StaticFiles(directory=static_files_path), name="static_assets"
|
||||
)
|
||||
|
||||
@react.get("/{path:path}")
|
||||
async def handle_catch_all(request: Request, path: str):
|
||||
fp = build_path / path
|
||||
if not fp.exists() or not fp.is_file():
|
||||
fp = build_path / "index.html"
|
||||
return fastapi.responses.FileResponse(fp)
|
||||
|
||||
return react
|
||||
return StaticFiles(directory=build_path, html=True)
|
||||
|
||||
|
||||
# Mount the frontend under /app to not conflict with the LangGraph API routes
|
||||
|
||||
Reference in New Issue
Block a user