rasAli02 commited on
Commit
7e8948c
Β·
1 Parent(s): ba2e359

πŸš€ Deployment: Resolve MongoDB SSL crash on Vercel by making startup resilient

Browse files
Files changed (1) hide show
  1. backend/app.py +5 -4
backend/app.py CHANGED
@@ -38,17 +38,18 @@ async def _init_db():
38
  try:
39
  from motor.motor_asyncio import AsyncIOMotorClient
40
  import certifi
 
41
  client = AsyncIOMotorClient(
42
  MONGO_URL,
43
  serverSelectionTimeoutMS=5000,
44
- tlsCAFile=certifi.where()
 
 
45
  )
46
- # Verify connection - Skip ping during startup to avoid Vercel timeouts
47
- # await client.admin.command("ping")
48
  _db = client["forgesight"]
49
  _inspections_col = _db["inspections"]
50
  _journal_col = _db["journal"]
51
- print("βœ… MongoDB client initialized")
52
  except Exception as e:
53
  print(f"⚠️ MongoDB unavailable ({e}) – using in-memory storage")
54
 
 
38
  try:
39
  from motor.motor_asyncio import AsyncIOMotorClient
40
  import certifi
41
+ # Try with standard SSL first
42
  client = AsyncIOMotorClient(
43
  MONGO_URL,
44
  serverSelectionTimeoutMS=5000,
45
+ tlsCAFile=certifi.where(),
46
+ # Fallback for environments with strict/broken SSL handshakes
47
+ tlsAllowInvalidCertificates=True
48
  )
 
 
49
  _db = client["forgesight"]
50
  _inspections_col = _db["inspections"]
51
  _journal_col = _db["journal"]
52
+ print("βœ… MongoDB client initialized (with TLS fallback)")
53
  except Exception as e:
54
  print(f"⚠️ MongoDB unavailable ({e}) – using in-memory storage")
55