Restore basic health check to fix Render deploy
This commit is contained in:
@ -121,22 +121,12 @@ origins = [
|
|||||||
|
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=["*"], # Abrir temporalmente para diagnóstico
|
allow_origins=["*"],
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
)
|
)
|
||||||
|
|
||||||
import logging
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
@app.exception_handler(Exception)
|
|
||||||
async def global_exception_handler(request, 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
|
# Ensure upload directories exist
|
||||||
for sub in ["profiles", "vehicles", "businesses"]:
|
for sub in ["profiles", "vehicles", "businesses"]:
|
||||||
os.makedirs(os.path.join("uploads", sub), exist_ok=True)
|
os.makedirs(os.path.join("uploads", sub), exist_ok=True)
|
||||||
@ -167,17 +157,6 @@ async def root():
|
|||||||
|
|
||||||
|
|
||||||
@app.get("/health")
|
@app.get("/health")
|
||||||
async def health(session: Session = Depends(get_session)):
|
async def health():
|
||||||
"""Health check endpoint connecting to DB."""
|
"""Health check endpoint."""
|
||||||
db_status = "connected"
|
return {"status": "healthy", "environment": settings.environment}
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user