forked from DigiFi/digifi-BankToProductCore
70 lines
1.7 KiB
Python
70 lines
1.7 KiB
Python
from re import U
|
|
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.eco.routes import eco
|
|
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)
|
|
|
|
# Swagger Doc
|
|
SWAGGER_URL = app.config.get("SWAGGER_URL")
|
|
API_URL = app.config.get("API_URL")
|
|
|
|
# Register blueprints
|
|
app.register_blueprint(api)
|
|
app.register_blueprint(eco, url_prefix="/eco")
|
|
|
|
swagger_ui_blueprint = get_swaggerui_blueprint(SWAGGER_URL, API_URL)
|
|
app.register_blueprint(swagger_ui_blueprint, url_prefix=SWAGGER_URL)
|
|
|
|
# Second UI (ECO)
|
|
eco_docs = "/eco" + SWAGGER_URL
|
|
eco_api = "/eco" + API_URL
|
|
swagger_ui_eco = get_swaggerui_blueprint(eco_docs, eco_api)
|
|
swagger_ui_eco.name = 'swagger_ui_eco' # Rename blueprint
|
|
app.register_blueprint(swagger_ui_eco, url_prefix=eco_docs)
|
|
|
|
# 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
|