mobadara commited on
Commit
bc1f6f8
·
1 Parent(s): 3bda825

editted database.py

Browse files
Files changed (1) hide show
  1. backend/database.py +19 -5
backend/database.py CHANGED
@@ -14,15 +14,29 @@ load_dotenv()
14
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
15
  logging.info('Environment variables loaded successfully.')
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  # MongoDB configuration
18
- MONGODB_URI = os.getenv('MONGODB_URI')
19
- DB_NAME = os.getenv('DATABASE_NAME')
20
 
21
  # Cloudinary Configuration
22
  cloudinary.config(
23
- cloud_name=os.getenv('CLOUDINARY_CLOUD_NAME'),
24
- api_key=os.getenv('CLOUDINARY_API_KEY'),
25
- api_secret=os.getenv('CLOUDINARY_API_SECRET'),
26
  secure=True
27
  )
28
 
 
14
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
15
  logging.info('Environment variables loaded successfully.')
16
 
17
+
18
+ def _get_env_var(*names: str) -> str:
19
+ """
20
+ Returns the first configured environment variable from a list of candidates.
21
+
22
+ Hugging Face Spaces exposes secrets as environment variables, so this helper
23
+ accepts both the original project names and common aliases.
24
+ """
25
+ for name in names:
26
+ value = os.getenv(name)
27
+ if value:
28
+ return value
29
+ raise RuntimeError(f"Missing required environment variable. Tried: {', '.join(names)}")
30
+
31
  # MongoDB configuration
32
+ MONGODB_URI = _get_env_var('MONGODB_URI', 'MONGO_URI')
33
+ DB_NAME = _get_env_var('DATABASE_NAME', 'DB_NAME')
34
 
35
  # Cloudinary Configuration
36
  cloudinary.config(
37
+ cloud_name=_get_env_var('CLOUDINARY_CLOUD_NAME'),
38
+ api_key=_get_env_var('CLOUDINARY_API_KEY'),
39
+ api_secret=_get_env_var('CLOUDINARY_API_SECRET'),
40
  secure=True
41
  )
42