forked from DigiFi/digifi-BankToProductCore
67 lines
1.6 KiB
Python
67 lines
1.6 KiB
Python
from flask import Flask
|
|
from flask_mail import Mail
|
|
import os
|
|
from flask_swagger_ui import get_swaggerui_blueprint
|
|
from flask_cors import CORS
|
|
from app.config import Config
|
|
from app.api.routes import api
|
|
from app.errors import register_error_handlers
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
from flask_migrate import Migrate
|
|
from app.extensions import db, migrate, mail
|
|
from flask_jwt_extended import (
|
|
JWTManager,
|
|
jwt_required,
|
|
create_access_token,
|
|
get_jwt_identity,
|
|
)
|
|
|
|
|
|
def create_app():
|
|
"""Factory function to create a Flask app instance"""
|
|
# import oracledb
|
|
|
|
# oracledb.init_oracle_client(lib_dir=None)
|
|
app = Flask(__name__)
|
|
|
|
# Load configuration
|
|
app.config.from_object(Config)
|
|
|
|
CORS(app)
|
|
JWTManager(app)
|
|
CORS(app, supports_credentials=True)
|
|
|
|
|
|
try:
|
|
# Swagger Doc
|
|
SWAGGER_URL = app.config.get("SWAGGER_URL")
|
|
API_URL = app.config.get("API_URL")
|
|
|
|
# Register blueprints
|
|
app.register_blueprint(api)
|
|
|
|
swagger_ui_blueprint = get_swaggerui_blueprint(SWAGGER_URL, API_URL)
|
|
app.register_blueprint(swagger_ui_blueprint, url_prefix=SWAGGER_URL)
|
|
|
|
except Exception as e:
|
|
print(f"Swagger Unexpected error occurred: {e}")
|
|
|
|
|
|
try:
|
|
# Error Handlers
|
|
register_error_handlers(app)
|
|
|
|
from . import models
|
|
|
|
# Initialize Flask-Mail
|
|
mail.init_app(app)
|
|
|
|
# Database and Migrations
|
|
db.init_app(app)
|
|
|
|
migrate.init_app(app, db)
|
|
|
|
return app
|
|
except Exception as e:
|
|
print(f"An unexpected error occurred: {e}")
|