"""Application. The API application is a `flask` application. It provides simple features such as registering a url for a specific handlers. """ from flask import Flask {% if cookiecutter.use_sql_db.lower() == 'y' %}from flask_sqlalchemy import SQLAlchemy{% endif %} from owslogger import flask_logger from owsrequest import flask_request from {{cookiecutter.app_name}} import config app = Flask(config.SERVICE_NAME) {% if cookiecutter.use_sql_db.lower() == 'y' %}app.config["SQLALCHEMY_DATABASE_URI"] = config.DB_URL app.config["SQLALCHEMY_ENGINE_OPTIONS"] = config.SQLALCHEMY_ENGINE_OPTIONS app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = config.SQLALCHEMY_TRACK_MODIFICATIONS db = SQLAlchemy(app){% endif %} flask_logger.setup( app, config.ENVIRONMENT, config.LOGGER_NAME, config.LOGGER_LEVEL, config.SERVICE_NAME, config.SERVICE_VERSION, exclude_paths=[config.HEALTH_CHECK], ) try: import uwsgi # noqa uwsgiRunning = True except ImportError: uwsgiRunning = False flask_request.setup( app, config.ENVIRONMENT, add_request_context=True, uwsgi_cache_enabled=uwsgiRunning) if config.ENVIRONMENT in [config.QA_ENVIRONMENT, config.PROD_ENVIRONMENT]: if not config.SENTRY: raise Exception(f"Sentry is not configured in {config.ENVIRONMENT}")