Use root url for monitoring url (#8506)

* 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>
This commit is contained in:
Abubakar Abid 2024-06-11 02:25:03 -07:00 committed by GitHub
parent 546d14e4f2
commit 7c5fec3a26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 4 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:Use root url for monitoring url

View File

@ -1167,11 +1167,12 @@ class App(FastAPI):
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}")

View File

@ -634,6 +634,30 @@ class TestAuthenticatedRoutes:
)
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