from flask import Flask from flask_restx import Api from .config import Config from .extensions import init_mongo, init_jwt from .errors.handlers import register_error_handlers from .routes.usage_routes import usage_ns from .routes.auth_routes import auth_ns from flask_cors import CORS def create_app(): app = Flask(__name__) app.config.from_object(Config) CORS(app, origins=app.config["FRONTEND_URL"], supports_credentials=True) init_mongo(app) init_jwt(app) api = Api( app, title='Trascription usage API', version='1.0', description='API documentation', doc='/docs', prefix='/api/v1', authorizations={ 'Bearer Auth': { 'type': 'apiKey', 'in': 'header', 'name': 'Authorization', 'description': "Enter your JWT token as: **Bearer <token>**" } } ) api.add_namespace(usage_ns, path='/usage') api.add_namespace(auth_ns, path='/auth') register_error_handlers(app) return app