Skip to content

Commit

Permalink
update gradio to modify the root to proxy to overwrite content
Browse files Browse the repository at this point in the history
  • Loading branch information
Sri Tikkireddy committed Sep 10, 2024
1 parent 192488a commit 4ee27be
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion dbtunnel/vendor/asgiproxy/frameworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,22 @@ def _make_gradio_local_proxy_config(
):
auth_config = auth_config or {}

def _modify_root(content, root_path):
list_of_uris = [b"/assets"]
for uri in list_of_uris:
content = content.replace(uri, root_path.encode("utf-8") + uri)
return content

def _modify_js_bundle(content, root_path):
list_of_uris = [b"/theme.css", b"/info", b"/queue", b"/assets"]
list_of_uris = [b"/theme.css", b"/info", b"/queue", b"/assets", b"/theme.css"]
for uri in list_of_uris:
content = content.replace(uri, root_path.rstrip("/").encode("utf-8") + uri)

content = content.replace(b'to:"/",', f'to:"{root_path}",'.encode("utf-8"))
return content

modify_js_bundle = functools.partial(_modify_js_bundle, root_path=url_base_path)
modify_root = functools.partial(_modify_root, root_path=url_base_path)

config = type(
"Config",
Expand All @@ -141,6 +148,7 @@ def _modify_js_bundle(content, root_path):
"upstream_base_url": f"http://{service_host}:{service_port}",
"rewrite_host_header": f"{service_host}:{service_port}",
"modify_content": {
"/": modify_root,
"*assets/index-*.js": modify_js_bundle,
# some reason gradio also has caps index bundled calling out explicitly
"*assets/Index-*.js": modify_js_bundle,
Expand Down

0 comments on commit 4ee27be

Please sign in to comment.