mirror of
http://88.130.71.182:3000/BlitTech/contexta_be.git
synced 2026-06-12 23:23:21 +00:00
fixed bugs
This commit is contained in:
28
app/main.py
28
app/main.py
@@ -1,3 +1,4 @@
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import JSONResponse
|
||||
@@ -13,13 +14,27 @@ logging.basicConfig(
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# ── App ────────────────────────────────────────────────────────────────────────
|
||||
|
||||
# BUG-13 FIX: Replace deprecated @app.on_event("startup") with lifespan
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# Startup
|
||||
logger.info("Contexta API starting up...")
|
||||
logger.info(f"Environment: {settings.app_env}")
|
||||
logger.info(f"Allowed origins: {settings.allowed_origins_list}")
|
||||
yield
|
||||
# Shutdown
|
||||
logger.info("Contexta API shutting down...")
|
||||
|
||||
|
||||
# ── App ──────────────────────────────────────────────────────────────────────────
|
||||
app = FastAPI(
|
||||
title="Contexta API",
|
||||
description="AI Chatbot Platform - Create, deploy and share custom AI chatbots powered by your data",
|
||||
version="1.0.0",
|
||||
docs_url="/docs",
|
||||
redoc_url="/redoc",
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
||||
# ── Middleware ─────────────────────────────────────────────────────────────────
|
||||
@@ -55,20 +70,13 @@ async def health():
|
||||
return {"status": "healthy", "environment": settings.app_env}
|
||||
|
||||
|
||||
# ── Sentry ────────────────────────────────────────────────────────────────────
|
||||
# ── Sentry ─────────────────────────────────────────────────────────────────────
|
||||
if settings.sentry_dsn:
|
||||
import sentry_sdk
|
||||
sentry_sdk.init(dsn=settings.sentry_dsn, traces_sample_rate=0.1)
|
||||
logger.info("Sentry initialized")
|
||||
|
||||
# ── Startup ───────────────────────────────────────────────────────────────────
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
logger.info("Contexta API starting up...")
|
||||
logger.info(f"Environment: {settings.app_env}")
|
||||
logger.info(f"Allowed origins: {settings.allowed_origins_list}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)
|
||||
uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)
|
||||
Reference in New Issue
Block a user