Files
digifi-BankEmulator/app/__init__.py
2025-07-30 05:16:47 +01:00

56 lines
1.5 KiB
Python

from re import S
from flask import Flask
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_jwt_extended import (
JWTManager,
jwt_required,
create_access_token,
get_jwt_identity,
)
def create_app():
""" Factory function to create a Flask app instance """
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 with /api prefix for the main API routes
app.register_blueprint(api, url_prefix="/api")
app.register_blueprint(eco, url_prefix="/eco")
# Swagger UI Blueprint
api_docs = "/api" + SWAGGER_URL
api_url = "/api" + API_URL
swagger_ui_api = get_swaggerui_blueprint(api_docs, api_url)
swagger_ui_api.name = 'swagger_ui_api' # Rename blueprint
app.register_blueprint(swagger_ui_api, url_prefix=api_docs)
# 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)
return app