36 lines
978 B
Python
Raw Permalink Normal View History

2025-07-14 13:42:58 +01:00
import os
from flask import Flask, jsonify
2025-07-14 13:42:58 +01:00
from dotenv import load_dotenv
from ktvmanager.config import DevelopmentConfig, ProductionConfig
from routes.api import api_blueprint
2025-07-14 18:32:48 +01:00
from ktvmanager.lib.database import initialize_db_pool
def create_app():
app = Flask(__name__)
2025-07-14 13:42:58 +01:00
load_dotenv()
if os.environ.get("FLASK_ENV") == "production":
app.config.from_object(ProductionConfig)
else:
app.config.from_object(DevelopmentConfig)
2025-07-14 18:32:48 +01:00
with app.app_context():
initialize_db_pool()
# Register blueprints
app.register_blueprint(api_blueprint)
# Error handlers
@app.errorhandler(404)
def not_found(error):
return jsonify({"error": "Not found"}), 404
@app.errorhandler(500)
def server_error(error):
return jsonify({"error": "Server error"}), 500
return app
if __name__ == "__main__":
app = create_app()
2025-07-14 13:42:58 +01:00
app.run(debug=app.config["DEBUG"], host=app.config["HOST"], port=app.config["PORT"])