Open amol- opened 5 days ago
Hi, does this also happen when you do demo.launch(root_path="/proxy")
instead of using gr.routes.App.create_app()
?
Hi, does this also happen when you do
demo.launch(root_path="/proxy")
instead of usinggr.routes.App.create_app()
?
When using demo.launch
it can't happen because you are setting the root_path
for the block itself. So while the app gets it overwritten by the block via configure_app
it doesn't have any impact as it gets actually overwritten with the expected one.
I think that configure_app
should copy the root_path from the block only when it's not empty
Describe the bug
The
root_path
setting is necessary to serve FastAPI applications under subpaths served via a proxy and the ASGI frameworks are expected to strip it from the request path during the routing process, see https://github.com/django/asgiref/issues/229#issuecomment-765583185But Gradio currently doesn't handle
root_path
correctly when set viacreate_app
thus making very hard to serve Gradio applications mounted in subpaths. This is probably related to https://github.com/gradio-app/gradio/issues/8073 https://github.com/gradio-app/gradio/issues/9101 and https://github.com/gradio-app/gradio/issues/9529When creating a Gradio application, it accepts additional options that are forwarded to the FastAPI application. This happens at https://github.com/gradio-app/gradio/blob/main/gradio/routes.py#L236
and is correctly exposed via the
create_app
factory https://github.com/gradio-app/gradio/blob/main/gradio/routes.py#L342But when trying to serve Gradio under subpath, setting the
root_path
viacreate_app
doesn't seem to do anything:The
root_path
is actually unset independently from the value provided, this is caused by theconfigure_app
method invoked by thecreate_app
factory: https://github.com/gradio-app/gradio/blob/main/gradio/routes.py#L345The
configure_app
overwrites the applicationroot_path
with whateverroot_path
the mounted block has (which is empty), thus making theroot_path
setting pointless: https://github.com/gradio-app/gradio/blob/main/gradio/routes.py#L298Have you searched existing issues? 🔎
Reproduction
with following NGinx configuration
(the same configuration works correctly if it's a FastAPI application instead of a Gradio application)
Screenshot
No response
Logs
No response
System Info
Severity
Blocking usage of gradio