-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
54 lines (43 loc) · 1.66 KB
/
app.py
File metadata and controls
54 lines (43 loc) · 1.66 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
52
53
54
from flask import Flask, jsonify
from flask_cors import CORS
from database import db
import os
# Import blueprints
from routes.media import media_bp
from routes.ai import ai_bp
from routes.stats import stats_bp
from routes.core import core_bp
def create_app(config_override=None):
app = Flask(__name__)
# Default Configuration
basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'show_tracker.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# Apply overrides before any DB initialization
if config_override:
app.config.update(config_override)
CORS(app, resources={r"/api/*": {"origins": "*"}})
db.init_app(app)
# Register Blueprints
app.register_blueprint(media_bp)
app.register_blueprint(ai_bp)
app.register_blueprint(stats_bp)
app.register_blueprint(core_bp)
# Only initialize DB if explicitly requested or if it's the main app entry
# For tests, we'll do this manually in the fixture
if not app.config.get('TESTING') and app.config.get('INIT_DB', True):
with app.app_context():
from utils.backup import backup_database
backup_database()
import models
db.create_all()
@app.errorhandler(Exception)
def handle_exception(e):
app.logger.error(f"Server Error: {str(e)}")
import traceback
app.logger.error(traceback.format_exc())
return jsonify({"error": "Internal Server Error", "details": str(e)}), 500
return app
if __name__ == '__main__':
app = create_app()
app.run(debug=True, port=5000)