65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
# ==============================================================================
|
|
# Punto de Entrada Principal FastAPI (OnEverControl)
|
|
# ==============================================================================
|
|
from datetime import datetime, timezone
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.middleware.gzip import GZipMiddleware
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from app.__version__ import __version__, __app_name__, __description__
|
|
from app.core.config import settings
|
|
from app.api.v1.router import api_router
|
|
|
|
|
|
# Creación de la instancia FastAPI
|
|
app = FastAPI(
|
|
title=__app_name__,
|
|
version=__version__,
|
|
description=__description__,
|
|
docs_url="/docs",
|
|
redoc_url="/redoc",
|
|
openapi_url="/openapi.json",
|
|
)
|
|
|
|
# Middleware de Compresión GZip (optimiza transferencia a tablets por Wi-Fi)
|
|
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
|
|
|
# Middleware de CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.ALLOWED_ORIGINS,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
@app.get("/health", tags=["Salud del Sistema"], summary="Verificar estado de salud del servicio")
|
|
async def health_check():
|
|
"""Retorna el estado de disponibilidad, versión y timestamp del servidor."""
|
|
return JSONResponse(
|
|
content={
|
|
"status": "ok",
|
|
"app": __app_name__,
|
|
"version": __version__,
|
|
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
}
|
|
)
|
|
|
|
|
|
@app.get("/", tags=["Información"], summary="Información del servicio")
|
|
async def root():
|
|
"""Ruta raíz informativa."""
|
|
return {
|
|
"app": __app_name__,
|
|
"version": __version__,
|
|
"docs": "/docs",
|
|
"health": "/health",
|
|
"api_v1": "/api/v1",
|
|
}
|
|
|
|
|
|
# Montaje de routers versionados
|
|
app.include_router(api_router, prefix="/api/v1")
|