36 lines
978 B
Python
36 lines
978 B
Python
import os
|
|
from flask import Flask, jsonify
|
|
from dotenv import load_dotenv
|
|
from ktvmanager.config import DevelopmentConfig, ProductionConfig
|
|
from routes.api import api_blueprint
|
|
from ktvmanager.lib.database import initialize_db_pool
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
load_dotenv()
|
|
|
|
if os.environ.get("FLASK_ENV") == "production":
|
|
app.config.from_object(ProductionConfig)
|
|
else:
|
|
app.config.from_object(DevelopmentConfig)
|
|
|
|
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()
|
|
app.run(debug=app.config["DEBUG"], host=app.config["HOST"], port=app.config["PORT"]) |