Skip to content

Commit

Permalink
Disable debug route by default
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-morvan committed Feb 17, 2025
1 parent 58fda1d commit 93437c0
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions backend/maelstro/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Main backend app setup
"""

import os
from typing import Annotated, Any
from fastapi import (
FastAPI,
Expand All @@ -27,6 +28,8 @@
)
from maelstro.common.models import SearchQuery

DEBUG = os.getenv("DEBUG", "False").lower() == "true"


app = FastAPI(root_path="/maelstro-backend")
setup_exception_handlers(app)
Expand Down Expand Up @@ -68,41 +71,40 @@ def user_page(
}


# pylint: disable=fixme
# TODO: deactivate for prod
@app.head("/debug")
@app.get("/debug")
@app.put("/debug")
@app.post("/debug")
@app.delete("/debug")
@app.options("/debug")
@app.patch("/debug")
async def debug_page(request: Request) -> dict[str, Any]:
"""
Display details of query including headers.
This may be useful in development to check all the headers provided by the gateway.
This entrypoint should be deactivated in prod.
"""
return {
**{
k: str(request.get(k))
for k in [
"method",
"type",
"asgi",
"http_version",
"server",
"client",
"scheme",
"url",
"base_url",
"root_path",
]
},
"data": await request.body(),
"headers": dict(request.headers),
"query_params": request.query_params.multi_items(),
}
if DEBUG:
@app.head("/debug")
@app.get("/debug")
@app.put("/debug")
@app.post("/debug")
@app.delete("/debug")
@app.options("/debug")
@app.patch("/debug")
async def debug_page(request: Request) -> dict[str, Any]:
"""
Display details of query including headers.
This may be useful in development to check all the headers provided by the gateway.
This entrypoint should be deactivated in prod.
"""
return {
**{
k: str(request.get(k))
for k in [
"method",
"type",
"asgi",
"http_version",
"server",
"client",
"scheme",
"url",
"base_url",
"root_path",
]
},
"data": await request.body(),
"headers": dict(request.headers),
"query_params": request.query_params.multi_items(),
}


@app.get("/check_config")
Expand Down

0 comments on commit 93437c0

Please sign in to comment.