Skip to content

Commit

Permalink
Use root url for monitoring url (#8506)
Browse files Browse the repository at this point in the history
* use root url for monitoring url

* add changeset

* format

* add unit test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
abidlabs and gradio-pr-bot authored Jun 11, 2024
1 parent 546d14e commit 7c5fec3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-cases-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Use root url for monitoring url
9 changes: 5 additions & 4 deletions gradio/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,11 +1167,12 @@ def robots_txt():
else:
return "User-agent: *\nDisallow: "

@app.get("/monitoring")
async def analytics_login():
print(
f"Monitoring URL: {app.get_blocks().local_url}monitoring/{app.analytics_key}"
@app.get("/monitoring", dependencies=[Depends(login_check)])
async def analytics_login(request: fastapi.Request):
root = route_utils.get_root_url(
request=request, route_path="/monitoring", root_path=app.root_path
)
print(f"Monitoring URL: {root}/monitoring/{app.analytics_key}")
return HTMLResponse("See console for monitoring URL.")

@app.get("/monitoring/{key}")
Expand Down
24 changes: 24 additions & 0 deletions test/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,30 @@ def test_logout(self):
)
assert response.status_code == 401

def test_monitoring_route(self):
io = Interface(lambda x: x, "text", "text")
app, _, _ = io.launch(
auth=("test", "correct_password"),
prevent_thread_lock=True,
)
client = TestClient(app)
client.post(
"/login",
data={"username": "test", "password": "correct_password"},
)

response = client.get(
"/monitoring",
)
assert response.status_code == 200

response = client.get("/logout")

response = client.get(
"/monitoring",
)
assert response.status_code == 401


class TestQueueRoutes:
@pytest.mark.asyncio
Expand Down

0 comments on commit 7c5fec3

Please sign in to comment.