52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
import logging
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from .api import chat
|
|
from .config import settings
|
|
from .services.provider_manager import provider_manager
|
|
|
|
# Setup logging
|
|
logging.basicConfig(level=logging.INFO)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
app = FastAPI(
|
|
title="DevDen API", description="AI chat backend for DevDen", version="1.0.0"
|
|
)
|
|
|
|
# CORS Configuration
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=[settings.FRONTEND_URL, "http://localhost:3000"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Include routers
|
|
app.include_router(chat.router)
|
|
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
"""Health check endpoint"""
|
|
return JSONResponse(
|
|
content={
|
|
"status": "healthy",
|
|
"providers": provider_manager.get_available_providers(),
|
|
}
|
|
)
|
|
|
|
|
|
@app.on_event("startup")
|
|
async def startup_event():
|
|
logger.info("DevDen API starting up...")
|
|
logger.info(f"Available providers: {provider_manager.get_available_providers()}")
|
|
|
|
|
|
@app.on_event("shutdown")
|
|
async def shutdown_event():
|
|
logger.info("DevDen API shutting down...")
|