56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
from typing import Any
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.openapi.utils import get_openapi
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from src.domain.contracts.openapi import inject_contract_schemas
|
|
from src.presentation.routes.articles import router as articles_router
|
|
from src.presentation.routes.auth import router as auth_router
|
|
from src.presentation.routes.sites import router as sites_router
|
|
|
|
|
|
app = FastAPI(title="AI Content Pipeline Backend")
|
|
app.include_router(auth_router)
|
|
app.include_router(articles_router)
|
|
app.include_router(sites_router)
|
|
|
|
|
|
@app.get("/health")
|
|
def health() -> dict[str, str]:
|
|
return {"service": "backend", "status": "ok"}
|
|
|
|
|
|
@app.get("/health/dependencies")
|
|
def dependency_health() -> JSONResponse:
|
|
from src.infrastructure.dependencies import check_dependencies
|
|
|
|
dependencies = check_dependencies()
|
|
is_ok = all(status == "ok" for status in dependencies.values())
|
|
|
|
return JSONResponse(
|
|
status_code=200 if is_ok else 503,
|
|
content={
|
|
"service": "backend",
|
|
"status": "ok" if is_ok else "error",
|
|
"dependencies": dependencies,
|
|
},
|
|
)
|
|
|
|
|
|
def custom_openapi() -> dict[str, Any]:
|
|
if app.openapi_schema:
|
|
return app.openapi_schema
|
|
|
|
openapi_schema = get_openapi(
|
|
title=app.title,
|
|
version=app.version,
|
|
routes=app.routes,
|
|
)
|
|
inject_contract_schemas(openapi_schema)
|
|
app.openapi_schema = openapi_schema
|
|
return app.openapi_schema
|
|
|
|
|
|
app.openapi = custom_openapi
|