Skip to content

Commit f783636

Browse files
committed
Add diagnostics API for debugging
1 parent 3cdf8ad commit f783636

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

backend/main.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Initalizing fastapi"""
22

3-
from fastapi import FastAPI
3+
from fastapi import FastAPI, Request
44
from fastapi.responses import FileResponse
55
from fastapi.staticfiles import StaticFiles
66

@@ -27,5 +27,35 @@ async def exception_404_handler(_, __):
2727
return FileResponse(f"{FRONTEND_PATH}/index.html")
2828

2929

30+
@app.get("/api/diagnostics")
31+
async def diagnostics(request: Request):
32+
"""
33+
Endpoint to display all diagnostic information about the incoming request.
34+
"""
35+
return {
36+
"method": request.method,
37+
"url": {
38+
"str": str(request.url),
39+
"is_secure": request.url.is_secure,
40+
"scheme": request.url.scheme,
41+
"netloc": {
42+
"str": request.url.netloc,
43+
"hostname": request.url.hostname,
44+
"port": request.url.port,
45+
},
46+
"path": request.url.path,
47+
"fragment": request.url.fragment,
48+
},
49+
"path_params": dict(request.path_params),
50+
"query_params": dict(request.query_params),
51+
"client": {
52+
"host": request.client.host if request.client else "UNKNOWN",
53+
"port": request.client.port if request.client else "UNKNOWN",
54+
},
55+
"headers": dict(request.headers),
56+
"cookies": request.cookies,
57+
}
58+
59+
3060
# serve frontend
3161
app.mount("/", StaticFiles(directory=FRONTEND_PATH, html=True), "frontend")

0 commit comments

Comments
 (0)