feat: стартовая HTML-страница / и favicon (было 404 JSON на корне)

This commit is contained in:
estorozhenko
2026-09-19 18:22:10 +00:00
parent 902ee91cf8
commit 6684d1653f
3 changed files with 38 additions and 1 deletions
+1
View File
@@ -13,6 +13,7 @@ COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/pytho
COPY --from=builder /usr/local/bin /usr/local/bin COPY --from=builder /usr/local/bin /usr/local/bin
COPY app/ app/ COPY app/ app/
COPY static/ static/
COPY .env.example .env COPY .env.example .env
# Read-only rootfs — только /data для БД и /logs для аудита # Read-only rootfs — только /data для БД и /logs для аудита
+36 -1
View File
@@ -6,11 +6,12 @@ import logging
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from fastapi import FastAPI, Request from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
from app.database import init_db from app.database import init_db
from app.api.v1 import router as api_v1_router from app.api.v1 import router as api_v1_router
from app.api.audit import AuditMiddleware from app.api.audit import AuditMiddleware
from pathlib import Path
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s") logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s")
logger = logging.getLogger("md2vk") logger = logging.getLogger("md2vk")
@@ -38,6 +39,40 @@ app.add_middleware(AuditMiddleware)
app.include_router(api_v1_router) app.include_router(api_v1_router)
STATIC_DIR = Path(__file__).resolve().parent.parent / "static"
@app.get("/favicon.ico", include_in_schema=False)
async def favicon() -> FileResponse:
"""Favicon (SVG-бренд)."""
return FileResponse(STATIC_DIR / "favicon.svg", media_type="image/svg+xml")
@app.get("/", response_class=HTMLResponse, include_in_schema=False)
async def index() -> HTMLResponse:
"""Стартовая страница сервиса."""
return HTMLResponse(
"""<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>md2vk</title>
<style>
body { font-family: system-ui, sans-serif; max-width: 640px; margin: 80px auto; padding: 0 20px;
background: #0d1117; color: #e6edf3; }
h1 { color: #58a6ff; }
code { background: #1f2630; padding: 2px 6px; border-radius: 4px; }
</style>
</head>
<body>
<h1>md2vk</h1>
<p>Сервис публикации Markdown на стену ВКонтакте.</p>
<p>API: <code>/api/v1</code> · <a href="/docs" style="color:#58a6ff">Swagger UI</a> · <a href="/redoc" style="color:#58a6ff">ReDoc</a></p>
</body>
</html>"""
)
@app.exception_handler(Exception) @app.exception_handler(Exception)
async def global_exception_handler(request: Request, exc: Exception): async def global_exception_handler(request: Request, exc: Exception):
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="6" fill="#0d1117"/><text x="16" y="22" font-family="Arial, sans-serif" font-size="16" font-weight="bold" fill="#58a6ff" text-anchor="middle">m</text></svg>

After

Width:  |  Height:  |  Size: 248 B