Update app.py
Browse files
app.py
CHANGED
|
@@ -30,7 +30,7 @@ def get_db_connection():
|
|
| 30 |
def initialize_db():
|
| 31 |
"""Initialize database with default entries"""
|
| 32 |
db = get_db_connection()
|
| 33 |
-
if
|
| 34 |
return False
|
| 35 |
|
| 36 |
collection = db[COLLECTION_NAME]
|
|
@@ -71,7 +71,7 @@ def index():
|
|
| 71 |
def admin():
|
| 72 |
"""Admin page to manage snippets"""
|
| 73 |
db = get_db_connection()
|
| 74 |
-
if
|
| 75 |
return "Database connection failed", 500
|
| 76 |
|
| 77 |
collection = db[COLLECTION_NAME]
|
|
@@ -88,7 +88,7 @@ def update_snippet():
|
|
| 88 |
return "Missing endpoint or text", 400
|
| 89 |
|
| 90 |
db = get_db_connection()
|
| 91 |
-
if
|
| 92 |
return "Database connection failed", 500
|
| 93 |
|
| 94 |
collection = db[COLLECTION_NAME]
|
|
@@ -142,7 +142,7 @@ def chiku4():
|
|
| 142 |
def get_snippet_response(endpoint):
|
| 143 |
"""Get snippet from database for given endpoint"""
|
| 144 |
db = get_db_connection()
|
| 145 |
-
if
|
| 146 |
return jsonify({"error": "Database connection failed"}), 500
|
| 147 |
|
| 148 |
collection = db[COLLECTION_NAME]
|
|
@@ -166,7 +166,7 @@ def replacement():
|
|
| 166 |
def health():
|
| 167 |
"""Health check endpoint"""
|
| 168 |
db = get_db_connection()
|
| 169 |
-
if db:
|
| 170 |
return jsonify({"status": "healthy", "database": "connected"})
|
| 171 |
else:
|
| 172 |
return jsonify({"status": "unhealthy", "database": "disconnected"}), 500
|
|
|
|
| 30 |
def initialize_db():
|
| 31 |
"""Initialize database with default entries"""
|
| 32 |
db = get_db_connection()
|
| 33 |
+
if db is None:
|
| 34 |
return False
|
| 35 |
|
| 36 |
collection = db[COLLECTION_NAME]
|
|
|
|
| 71 |
def admin():
|
| 72 |
"""Admin page to manage snippets"""
|
| 73 |
db = get_db_connection()
|
| 74 |
+
if db is None:
|
| 75 |
return "Database connection failed", 500
|
| 76 |
|
| 77 |
collection = db[COLLECTION_NAME]
|
|
|
|
| 88 |
return "Missing endpoint or text", 400
|
| 89 |
|
| 90 |
db = get_db_connection()
|
| 91 |
+
if db is None:
|
| 92 |
return "Database connection failed", 500
|
| 93 |
|
| 94 |
collection = db[COLLECTION_NAME]
|
|
|
|
| 142 |
def get_snippet_response(endpoint):
|
| 143 |
"""Get snippet from database for given endpoint"""
|
| 144 |
db = get_db_connection()
|
| 145 |
+
if db is None:
|
| 146 |
return jsonify({"error": "Database connection failed"}), 500
|
| 147 |
|
| 148 |
collection = db[COLLECTION_NAME]
|
|
|
|
| 166 |
def health():
|
| 167 |
"""Health check endpoint"""
|
| 168 |
db = get_db_connection()
|
| 169 |
+
if db is not None:
|
| 170 |
return jsonify({"status": "healthy", "database": "connected"})
|
| 171 |
else:
|
| 172 |
return jsonify({"status": "unhealthy", "database": "disconnected"}), 500
|