-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
51 lines (41 loc) · 1.35 KB
/
Copy pathapp.py
File metadata and controls
51 lines (41 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import logging
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase
from werkzeug.middleware.proxy_fix import ProxyFix
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
class Base(DeclarativeBase):
pass
db = SQLAlchemy(model_class=Base)
# Create the app
app = Flask(__name__)
app.secret_key = os.environ.get("SESSION_SECRET", "dev-secret-key-change-in-production")
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
# Configure the database
database_url = os.environ.get("DATABASE_URL")
if database_url and database_url.startswith("postgresql://"):
# PostgreSQL for production
database_url = database_url.replace("postgresql://", "postgresql+psycopg2://")
app.config["SQLALCHEMY_DATABASE_URI"] = database_url
else:
# SQLite for development
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///poetry_music.db"
app.config["SQLALCHEMY_ENGINE_OPTIONS"] = {
"pool_recycle": 300,
"pool_pre_ping": True,
}
# Initialize the app with the extension
db.init_app(app)
# Import routes
from routes import *
with app.app_context():
# Import models to ensure tables are created
import models
db.create_all()
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=False)