Spaces:
Sleeping
Sleeping
Make MongoDB optional - show warning instead of crashing
Browse files
server.py
CHANGED
|
@@ -322,10 +322,15 @@ async def startup_event():
|
|
| 322 |
mongo_uri = os.getenv("MONGODB_URI", "mongodb://localhost:27017")
|
| 323 |
mongo_db_name = os.getenv("MONGODB_DB", "afs")
|
| 324 |
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
|
| 330 |
asyncio.create_task(vcam_generator_loop())
|
| 331 |
|
|
|
|
| 322 |
mongo_uri = os.getenv("MONGODB_URI", "mongodb://localhost:27017")
|
| 323 |
mongo_db_name = os.getenv("MONGODB_DB", "afs")
|
| 324 |
|
| 325 |
+
try:
|
| 326 |
+
mongo_client = AsyncMongoClient(mongo_uri, serverSelectionTimeoutMS=5000)
|
| 327 |
+
users_collection = mongo_client[mongo_db_name]["users"]
|
| 328 |
+
await users_collection.create_index("email", unique=True)
|
| 329 |
+
logger.info("Connected to MongoDB and initialized users index.")
|
| 330 |
+
except Exception as e:
|
| 331 |
+
logger.warning(f"MongoDB connection failed: {e}. Running without authentication.")
|
| 332 |
+
mongo_client = None
|
| 333 |
+
users_collection = None
|
| 334 |
|
| 335 |
asyncio.create_task(vcam_generator_loop())
|
| 336 |
|