feat: Enhance route logging to include mounted apps and unknown route types for better debugging

This commit is contained in:
Slipstream 2025-05-14 17:16:12 -06:00
parent 7799588aaa
commit c06a81503f
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -525,8 +525,14 @@ try:
app.mount("/webhook", webhook_router) # Mount directly on the main app for simplicity
# After mounting the webhook router
log.info("Available routes in webhook_router:")
from fastapi.routing import APIRoute, Mount
for route in webhook_router.routes:
if isinstance(route, APIRoute):
log.info(f" {route.path} - {route.name} - {route.methods}")
elif isinstance(route, Mount):
log.info(f" {route.path} - {route.name} - Mounted app or static files")
else:
log.info(f" {route.path} - {route.name} - Unknown route type")
# Or, if you prefer to nest it under /api:
# api_app.include_router(webhook_router, prefix="/webhooks", tags=["Webhooks"])
log.info("Webhook endpoints loaded and mounted successfully at /webhook")
@ -551,8 +557,14 @@ except ImportError as e:
# Log the available routes for debugging
log.info("Available routes in dashboard_api_app:")
from fastapi.routing import APIRoute, Mount
for route in dashboard_api_app.routes:
if isinstance(route, APIRoute):
log.info(f" {route.path} - {route.name} - {route.methods}")
elif isinstance(route, Mount):
log.info(f" {route.path} - {route.name} - Mounted app or static files")
else:
log.info(f" {route.path} - {route.name} - Unknown route type")
# Create a middleware for redirecting /discordapi to /api with a deprecation warning
class DeprecationRedirectMiddleware(BaseHTTPMiddleware):
@ -610,8 +622,14 @@ async def verify_discord_token(authorization: str = Header(None)) -> str:
# Log the available routes for debugging
log.info("Available routes in main app:")
from fastapi.routing import APIRoute, Mount
for route in app.routes:
if isinstance(route, APIRoute):
log.info(f" {route.path} - {route.name} - {route.methods}")
elif isinstance(route, Mount):
log.info(f" {route.path} - {route.name} - Mounted app or static files")
else:
log.info(f" {route.path} - {route.name} - Unknown route type")
@app.get("/")
async def root():