from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.staticfiles import StaticFiles from fastapi.responses import FileResponse from backend.app.api.v1.routes import router as api_router from backend.app.config import settings import os app = FastAPI( title="RAG System API", description="Production-grade RAG system with PDF document processing and web search", version="1.0.0", docs_url="/api/docs", redoc_url="/api/redoc", ) app.add_middleware( CORSMiddleware, allow_origins=settings.CORS_ORIGINS, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) app.include_router(api_router, prefix="/api/v1") # Serve static files (React frontend) frontend_path = os.path.join(os.path.dirname(__file__), "../../frontend/dist") try: if os.path.exists(frontend_path): app.mount("/", StaticFiles(directory=frontend_path, html=True), name="static") except Exception: pass @app.get("/") async def serve_index(): index_path = os.path.join(frontend_path, "index.html") if os.path.exists(index_path): return FileResponse(index_path) return {"message": "RAG System API", "version": "1.0.0"} @app.get("/health") async def health_check(): return {"status": "healthy", "service": "RAG System"}