File size: 1,571 Bytes
3557eaa
 
62a1756
 
 
 
 
3557eaa
 
62a1756
 
3557eaa
62a1756
3557eaa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62a1756
 
 
3557eaa
 
 
 
62a1756
 
 
 
 
 
 
 
3557eaa
62a1756
 
3557eaa
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.auth.routes import router as auth_router
from app.rag.routes import router as rag_router
from app.logging_config import setup_logging
from app.rabbitmq.connection import rabbitmq
from app.rabbitmq.consumers import start_consumers

setup_logging()
logger = logging.getLogger(__name__)


@asynccontextmanager
async def lifespan(app: FastAPI):
    # ── Startup ──
    logger.info("Connecting to RabbitMQ...")
    await rabbitmq.connect()
    await start_consumers()
    yield
    # ── Shutdown ──
    logger.info("Disconnecting from RabbitMQ...")
    await rabbitmq.disconnect()


app = FastAPI(
    title="EchoLoft AI API",
    description="SaaS RAG Chat with Groq + RabbitMQ event streaming",
    version="1.2.0",
    lifespan=lifespan,
)

app.add_middleware(
    CORSMiddleware,
    allow_origins=[
        "http://localhost:3000",
        "https://echoloftai.vercel.app",
    ],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(auth_router)
app.include_router(rag_router, prefix="/rag")


@app.get("/")
async def root():
    return {
        "message": "Welcome to EchoLoft AI API",
        "version": "1.2.0",
        "rabbitmq": "connected" if rabbitmq.is_connected else "disconnected",
    }


@app.get("/health")
async def health():
    return {
        "status": "ok",
        "rabbitmq": "connected" if rabbitmq.is_connected else "disconnected",
    }