Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
set up Gunicorn logging
make db initialization happen once instead of on every runner
  • Loading branch information
LucifersCircle committed Dec 7, 2024
1 parent 69f4384 commit 6fbdcef
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
import re
import sqlite3
import hashlib
import logging

from flask import Flask, request, jsonify, render_template_string
from cryptography.fernet import Fernet

app = Flask(__name__)

# Set up logging for Gunicorn
if __name__ != '__main__':
gunicorn_logger = logging.getLogger('gunicorn.error')
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(gunicorn_logger.level)

# Get encryption key from environment variable
encryption_key = os.getenv('ENCRYPTION_KEY')
if not encryption_key:
Expand Down Expand Up @@ -43,9 +50,6 @@ def initialize_db():
except Exception as e:
print(f"Error initializing database: {e}", flush=True)

# Initialize database on startup
initialize_db()

# HTML template for the landing page
HTML_TEMPLATE = """
<!DOCTYPE html>
Expand Down Expand Up @@ -143,8 +147,6 @@ def initialize_db():
"""



# Landing page route
@app.route('/', methods=['GET', 'POST'])
def manage_key():
Expand Down Expand Up @@ -226,4 +228,5 @@ def manage_key():


if __name__ == '__main__':
initialize_db() # Initialize database on startup
app.run(host='0.0.0.0', port=5000)

0 comments on commit 6fbdcef

Please sign in to comment.