.
This commit is contained in:
@@ -1,25 +1,11 @@
|
||||
"""
|
||||
Copyright 2025 Google. This software is provided as-is, without warranty or
|
||||
representation for any use or purpose. Your use of it is subject to your
|
||||
agreement with Google.
|
||||
|
||||
Main FastAPI application.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from .config import get_settings
|
||||
from .controllers import (
|
||||
conversation_router,
|
||||
notification_router,
|
||||
llm_webhook_router,
|
||||
quick_replies_router,
|
||||
data_purge_router,
|
||||
)
|
||||
from .config import settings
|
||||
from .routers import conversation_router, notification_router, quick_replies_router
|
||||
from .dependencies import init_services, startup_services, shutdown_services
|
||||
|
||||
|
||||
@@ -32,10 +18,9 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
async def lifespan(_: FastAPI):
|
||||
"""Application lifespan manager."""
|
||||
# Startup
|
||||
settings = get_settings()
|
||||
logger.info("Initializing services...")
|
||||
init_services(settings)
|
||||
await startup_services()
|
||||
@@ -49,41 +34,33 @@ async def lifespan(app: FastAPI):
|
||||
logger.info("Application shutdown complete")
|
||||
|
||||
|
||||
def create_app() -> FastAPI:
|
||||
"""Create and configure FastAPI application."""
|
||||
app = FastAPI(
|
||||
title="Capa de Integración - Orchestrator Service",
|
||||
description="Conversational AI orchestrator for Dialogflow CX, Gemini, and Vertex AI",
|
||||
version="0.1.0",
|
||||
lifespan=lifespan,
|
||||
)
|
||||
app = FastAPI(
|
||||
title="Capa de Integración - Orchestrator Service",
|
||||
description="Conversational AI orchestrator for Dialogflow CX, Gemini, and Vertex AI",
|
||||
version="0.1.0",
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
||||
# CORS middleware
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"], # Configure appropriately for production
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
# CORS middleware
|
||||
# Note: Type checker reports false positive for CORSMiddleware
|
||||
# This is the correct FastAPI pattern per official documentation
|
||||
app.add_middleware(
|
||||
CORSMiddleware, # ty: ignore
|
||||
allow_origins=["*"], # Configure appropriately for production
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# Register routers
|
||||
app.include_router(conversation_router)
|
||||
app.include_router(notification_router)
|
||||
app.include_router(llm_webhook_router)
|
||||
app.include_router(quick_replies_router)
|
||||
app.include_router(data_purge_router)
|
||||
# Register routers
|
||||
app.include_router(conversation_router)
|
||||
app.include_router(notification_router)
|
||||
app.include_router(quick_replies_router)
|
||||
|
||||
@app.get("/health")
|
||||
async def health_check():
|
||||
"""Health check endpoint."""
|
||||
return {"status": "healthy", "service": "capa-de-integracion"}
|
||||
|
||||
return app
|
||||
|
||||
|
||||
# Create app instance
|
||||
app = create_app()
|
||||
@app.get("/health")
|
||||
async def health_check():
|
||||
"""Health check endpoint."""
|
||||
return {"status": "healthy", "service": "capa-de-integracion"}
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user