clausewatch-api / main.py
Nilyzz's picture
Update backend
357db8c
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")