Skip to content

Commit

Permalink
Add diagnostics API for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ankith26 committed Dec 20, 2024
1 parent 3cdf8ad commit f783636
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion backend/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Initalizing fastapi"""

from fastapi import FastAPI
from fastapi import FastAPI, Request
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles

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


@app.get("/api/diagnostics")
async def diagnostics(request: Request):
"""
Endpoint to display all diagnostic information about the incoming request.
"""
return {
"method": request.method,
"url": {
"str": str(request.url),
"is_secure": request.url.is_secure,
"scheme": request.url.scheme,
"netloc": {
"str": request.url.netloc,
"hostname": request.url.hostname,
"port": request.url.port,
},
"path": request.url.path,
"fragment": request.url.fragment,
},
"path_params": dict(request.path_params),
"query_params": dict(request.query_params),
"client": {
"host": request.client.host if request.client else "UNKNOWN",
"port": request.client.port if request.client else "UNKNOWN",
},
"headers": dict(request.headers),
"cookies": request.cookies,
}


# serve frontend
app.mount("/", StaticFiles(directory=FRONTEND_PATH, html=True), "frontend")

0 comments on commit f783636

Please sign in to comment.