Spaces:
Sleeping
Sleeping
File size: 1,138 Bytes
357db8c 306e475 357db8c 306e475 357db8c 306e475 357db8c 306e475 357db8c 306e475 357db8c 306e475 357db8c 306e475 357db8c 306e475 357db8c 306e475 357db8c | 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 | import logging
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
from app.core.database import engine, Base
from app.api.routes import router as api_router
# Logging Configuration
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Create tables
Base.metadata.create_all(bind=engine)
app = FastAPI(
title="ClauseWatch AI API",
version="1.0.0",
)
# CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:3000", "https://clause-watch-ia.vercel.app"],
allow_credentials=True,
allow_methods=["GET", "POST", "OPTIONS"],
allow_headers=["*"],
)
# Global Exception Handler
@app.exception_handler(Exception)
async def global_exception_handler(request: Request, exc: Exception):
logger.error(f"CRITICAL ERROR at {request.url}: {exc}", exc_info=True)
return JSONResponse(
status_code=500,
content={"detail": "An internal server error occurred."},
)
@app.get("/")
def health_check():
return {"status": "ok"}
app.include_router(api_router, prefix="/api/v1") |