33 lines
849 B
Python
33 lines
849 B
Python
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.errors import register_error_handlers
|
|
|
|
def create_app():
|
|
""" Factory function to create a Flask app instance """
|
|
app = Flask(__name__)
|
|
|
|
# Load configuration
|
|
app.config.from_object(Config)
|
|
|
|
CORS(app)
|
|
|
|
# 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')
|
|
|
|
swagger_ui_blueprint = get_swaggerui_blueprint(SWAGGER_URL, API_URL)
|
|
app.register_blueprint(swagger_ui_blueprint, url_prefix=SWAGGER_URL)
|
|
|
|
|
|
# Error Handlers
|
|
register_error_handlers(app)
|
|
|
|
return app
|