Primi files backend

This commit is contained in:
2026-04-28 17:17:51 +02:00
parent 1ede1d14ab
commit 19bf96d534
12 changed files with 426 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
from contextlib import asynccontextmanager
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
import structlog
from app.api import auth, health, vehicles, valuations
from app.core.database import engine
from app.core import database as db_module
logger = structlog.get_logger()
@asynccontextmanager
async def lifespan(app: FastAPI):
logger.info("Avvio GMG Smart Quote backend")
yield
await engine.dispose()
logger.info("Shutdown completo")
app = FastAPI(
title="GMG Smart Quote API",
version="1.0.0",
lifespan=lifespan,
)
app.add_middleware(
CORSMiddleware,
allow_origins=[
"http://localhost:3000",
"http://localhost:3001",
"http://localhost:5173",
"http://127.0.0.1:3000",
"http://127.0.0.1:3001",
],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.exception_handler(Exception)
async def global_exception_handler(request: Request, exc: Exception):
logger.error("Unhandled exception", path=request.url.path, error=str(exc))
return JSONResponse(
status_code=500,
content={"detail": "Errore interno del server"},
)
app.include_router(auth.router, prefix="/api/auth", tags=["auth"])
app.include_router(health.router, prefix="/api", tags=["health"])
app.include_router(vehicles.router, prefix="/api/vehicles", tags=["vehicles"])
app.include_router(valuations.router, prefix="/api/valuations", tags=["valuations"])