37 lines
951 B
Python
37 lines
951 B
Python
from flask import Flask
|
|
from flask_mail import Mail
|
|
from flask_cors import CORS
|
|
from app.config import Config
|
|
from app.routes import auth_bp, autocall_bp
|
|
from app.response import (method_not_allowed, unsupported_media_type, not_found, bad_request)
|
|
from app.extensions import db, mail
|
|
|
|
|
|
def create_app():
|
|
"""Factory function to create a Flask app instance"""
|
|
app = Flask(__name__)
|
|
|
|
# Load configuration
|
|
app.config.from_object(Config)
|
|
|
|
# Setup CORS
|
|
CORS(app)
|
|
|
|
# Initialize Flask-Mail
|
|
mail.init_app(app)
|
|
|
|
# Register blueprints
|
|
app.register_blueprint(auth_bp)
|
|
app.register_blueprint(autocall_bp, url_prefix="/autocall")
|
|
|
|
# Error Handlers
|
|
app.register_error_handler(405, method_not_allowed)
|
|
app.register_error_handler(415, unsupported_media_type)
|
|
app.register_error_handler(404, not_found)
|
|
app.register_error_handler(400, bad_request)
|
|
|
|
# Database
|
|
db.init_app(app)
|
|
|
|
return app
|