-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
46 lines (38 loc) · 1.46 KB
/
Copy pathapp.py
File metadata and controls
46 lines (38 loc) · 1.46 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
import os
from flask import Flask
from routes.games import games_bp
from routes.auth import auth_bp
from models import db
from utils.database import get_connection_string
from utils.seed_database import seed_database
# Get the server directory path
base_dir: str = os.path.abspath(os.path.dirname(__file__))
app: Flask = Flask(__name__)
# Configure and initialize the database
app.config['SQLALCHEMY_DATABASE_URI'] = get_connection_string()
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
# Create tables and seed data (idempotent — skips existing records)
with app.app_context():
db.create_all()
seed_database()
# Register blueprints
app.register_blueprint(games_bp)
app.register_blueprint(auth_bp)
def _env_flag(name: str, default: bool = False) -> bool:
value: str = os.environ.get(name, "").strip().lower()
if not value:
return default
return value in {"1", "true", "yes", "on"}
if __name__ == '__main__':
# Hot-reload is on by default; the interactive Werkzeug debugger is opt-in
# via FLASK_INTERACTIVE_DEBUGGER because it requires POSIX semaphores that
# are blocked under some sandboxed environments.
use_reloader: bool = _env_flag("FLASK_DEBUG", default=True)
use_debugger: bool = _env_flag("FLASK_INTERACTIVE_DEBUGGER", default=False)
app.run(
host='0.0.0.0',
port=5100, # Port 5100 to avoid macOS conflicts
use_reloader=use_reloader,
use_debugger=use_debugger,
)