Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added services/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added services/api/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added services/api/app/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added services/api/app/__pycache__/main.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
62 changes: 61 additions & 1 deletion services/api/app/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from fastapi import FastAPI
from fastapi.openapi.docs import get_swagger_ui_html, get_redoc_html
from fastapi.responses import HTMLResponse

from services.api.app.models import CheckTransactionRequest, CheckTransactionResponse
from services.intelligence.sentinel_risk.engine import (
Expand All @@ -11,7 +13,12 @@

POLICY_VERSION = "day13-v3"

app = FastAPI(title="SentinelAI API", version="0.1.0")
app = FastAPI(
title="SentinelAI API",
version="0.1.0",
docs_url=None, # Disable default docs to use custom ones with Speed Insights
redoc_url=None, # Disable default redoc to use custom ones with Speed Insights
)


@app.get("/health", tags=["system"])
Expand Down Expand Up @@ -50,3 +57,56 @@ def check_transaction(request: CheckTransactionRequest) -> CheckTransactionRespo
decision=decision.value,
policy_version=POLICY_VERSION,
)


@app.get("/docs", include_in_schema=False)
async def custom_swagger_ui_html() -> HTMLResponse:
"""
Custom Swagger UI with Vercel Speed Insights integration.
"""
html = get_swagger_ui_html(
openapi_url=app.openapi_url or "/openapi.json",
title=f"{app.title} - Swagger UI",
swagger_js_url="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.9.0/swagger-ui-bundle.js",
swagger_css_url="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.9.0/swagger-ui.css",
swagger_favicon_url="https://fastapi.tiangolo.com/img/favicon.png",
# Inject Vercel Speed Insights script
swagger_ui_parameters={
"persistAuthorization": True,
},
)
# Inject Speed Insights script into the HTML
html_content = html.body.decode()
html_content = html_content.replace(
"</head>",
"""<script>
window.si = window.si || function () { (window.siq = window.siq || []).push(arguments); };
</script>
<script defer src="/_vercel/speed-insights/script.js"></script>
</head>""",
)
return HTMLResponse(content=html_content)


@app.get("/redoc", include_in_schema=False)
async def custom_redoc_html() -> HTMLResponse:
"""
Custom ReDoc with Vercel Speed Insights integration.
"""
html = get_redoc_html(
openapi_url=app.openapi_url or "/openapi.json",
title=f"{app.title} - ReDoc",
redoc_js_url="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js",
redoc_favicon_url="https://fastapi.tiangolo.com/img/favicon.png",
)
# Inject Speed Insights script into the HTML
html_content = html.body.decode()
html_content = html_content.replace(
"</head>",
"""<script>
window.si = window.si || function () { (window.siq = window.siq || []).push(arguments); };
</script>
<script defer src="/_vercel/speed-insights/script.js"></script>
</head>""",
)
return HTMLResponse(content=html_content)
Loading