From 8f021c55b00a07feabab2bf3259299d794bfeb25 Mon Sep 17 00:00:00 2001 From: Hanzo_dev <2002samudiojohan@gmail.com> Date: Wed, 25 Feb 2026 11:55:07 -0500 Subject: [PATCH] Allow all origins and add DB check to health endpoint --- backend/app/main.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/backend/app/main.py b/backend/app/main.py index 9744393..4f3a536 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -121,8 +121,7 @@ origins = [ app.add_middleware( CORSMiddleware, - allow_origins=origins, - allow_origin_regex="https://.*sibu.*\.vercel\.app", # Permitir subdominios de vercel con 'sibu' + allow_origins=["*"], # Abrir temporalmente para diagnóstico allow_credentials=True, allow_methods=["*"], allow_headers=["*"], @@ -134,8 +133,9 @@ logger = logging.getLogger(__name__) @app.exception_handler(Exception) async def global_exception_handler(request, exc): - logger.error(f"Global error: {exc}", exc_info=True) - return {"detail": "Internal Server Error", "message": str(exc)} + # Loguear de forma segura sin caracteres especiales que rompan el terminal + logger.error(f"Global error on {request.url.path}: {str(exc)}") + return {"detail": "Internal Server Error", "message": "Verify database connection or payload"} # Ensure upload directories exist for sub in ["profiles", "vehicles", "businesses"]: @@ -167,6 +167,17 @@ async def root(): @app.get("/health") -async def health(): - """Health check endpoint.""" - return {"status": "healthy", "environment": settings.environment} +async def health(session: Session = Depends(get_session)): + """Health check endpoint connecting to DB.""" + db_status = "connected" + try: + from sqlalchemy import text + session.execute(text("SELECT 1")) + except Exception as e: + db_status = f"disconnected: {str(e)}" + + return { + "status": "healthy" if db_status == "connected" else "degraded", + "environment": settings.environment, + "database": db_status + }