openhands commited on
Commit
14690be
·
1 Parent(s): c744cbf

Fix root route redirect to /home

Browse files

The root FastAPI app needs an explicit handler for / to redirect to
/home since Gradio multi-page apps don't handle the bare root path.

Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -380,11 +380,18 @@ logger.info("All routes configured")
380
 
381
  # Mount the REST API on /api
382
  from fastapi import FastAPI
 
383
  from api import api_app
384
 
385
  # Create a parent FastAPI app that will host both the API and Gradio
386
  root_app = FastAPI()
387
  root_app.mount("/api", api_app)
 
 
 
 
 
 
388
  app = gr.mount_gradio_app(root_app, demo, path="/")
389
  logger.info("REST API mounted at /api, Gradio app mounted at /")
390
 
 
380
 
381
  # Mount the REST API on /api
382
  from fastapi import FastAPI
383
+ from fastapi.responses import RedirectResponse
384
  from api import api_app
385
 
386
  # Create a parent FastAPI app that will host both the API and Gradio
387
  root_app = FastAPI()
388
  root_app.mount("/api", api_app)
389
+
390
+ # Add redirect from / to /home (Gradio's multi-page apps need explicit routes)
391
+ @root_app.get("/", include_in_schema=False)
392
+ async def root_redirect():
393
+ return RedirectResponse(url="/home")
394
+
395
  app = gr.mount_gradio_app(root_app, demo, path="/")
396
  logger.info("REST API mounted at /api, Gradio app mounted at /")
397