Varun10000's picture
Upload 50 files
e33a96e verified
Raw
History Blame Contribute Delete
2.33 kB
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
from app.database import engine, Base
from app.routers import knowledge_base, rfp_processing, chatbot, health
from pathlib import Path
import os
# Create database tables
Base.metadata.create_all(bind=engine)
app = FastAPI(
title="RFP Management System",
description="AI-powered RFP management with intelligent answer generation",
version="1.0.0"
)
# CORS middleware for frontend
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173", "http://localhost:5174", "http://localhost:3000"], # SvelteKit default ports
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include routers
app.include_router(health.router)
app.include_router(knowledge_base.router)
app.include_router(rfp_processing.router)
app.include_router(chatbot.router)
# Serve static frontend files
FRONTEND_BUILD_DIR = Path(__file__).parent.parent.parent / "frontend" / "build"
# Check if we're in deployment (frontend/build exists at different path)
if not FRONTEND_BUILD_DIR.exists():
# In Docker deployment, frontend is at /app/frontend/build
FRONTEND_BUILD_DIR = Path("/app/frontend/build")
if FRONTEND_BUILD_DIR.exists():
# Mount static files
app.mount("/_app", StaticFiles(directory=str(FRONTEND_BUILD_DIR / "_app")), name="app-assets")
# Serve index.html for root and all other routes (SPA fallback)
@app.get("/")
async def serve_frontend():
return FileResponse(str(FRONTEND_BUILD_DIR / "index.html"))
@app.get("/{full_path:path}")
async def serve_spa(full_path: str):
# Serve static files if they exist
file_path = FRONTEND_BUILD_DIR / full_path
if file_path.is_file():
return FileResponse(str(file_path))
# Otherwise serve index.html for SPA routing
return FileResponse(str(FRONTEND_BUILD_DIR / "index.html"))
else:
# Fallback if frontend not found
@app.get("/")
def read_root():
return {
"message": "RFP Management System API",
"version": "1.0.0",
"docs": "/docs"
}