mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-12 12:40:29 +08:00
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:
parent
546d14e4f2
commit
7c5fec3a26
5
.changeset/hot-cases-sneeze.md
Normal file
5
.changeset/hot-cases-sneeze.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:Use root url for monitoring url
|
@ -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}")
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user