Exemple #1
0
def create_app(env=os.environ.get("FLASK_ENV")):
    """Application factory."""
    logging.basicConfig(
        level=logging.INFO,
        format=("[%(asctime)s] [sev %(levelno)s] [%(levelname)s] "
                "[%(name)s]> %(message)s"),
        datefmt="%a, %d %b %Y %H:%M:%S")

    # Disable werkzeug logging under WARNING.
    logging.getLogger("werkzeug").setLevel(logging.WARNING)

    app = Flask(__name__)

    app.logger.info(f"Loading env {env}")
    configurations = {
        "dev-local": "shhh.config.DefaultConfig",
        "dev-docker": "shhh.config.DockerConfig",
        "heroku": "shhh.config.HerokuConfig",
        "production": "shhh.config.ProductionConfig",
    }
    app.config.from_object(
        configurations.get(env, "shhh.config.ProductionConfig"))

    db.init_app(app)
    scheduler.init_app(app)

    with app.app_context():
        register_blueprints(app)
        db.create_all()
        scheduler.start()

        from shhh import views

    return app
Exemple #2
0
def create_app(env=os.environ.get("FLASK_ENV")):
    """Application factory."""
    logging.basicConfig(
        level=logging.INFO,
        format=
        ("[%(asctime)s] [sev %(levelno)s] [%(levelname)s] [%(name)s]> %(message)s"
         ),
        datefmt="%a, %d %b %Y %H:%M:%S",
    )

    if env == EnvConfig.TESTING.value:
        logging.getLogger("shhh").setLevel(logging.CRITICAL)
        logging.getLogger("apscheduler").setLevel(logging.CRITICAL)
        logging.getLogger("tasks").setLevel(logging.CRITICAL)

    app = Flask(__name__)

    configurations = {
        EnvConfig.TESTING.value: "shhh.config.TestConfig",
        EnvConfig.DEV_LOCAL.value: "shhh.config.DefaultConfig",
        EnvConfig.DEV_DOCKER.value: "shhh.config.DockerConfig",
        EnvConfig.HEROKU.value: "shhh.config.HerokuConfig",
        EnvConfig.PRODUCTION.value: "shhh.config.ProductionConfig",
    }
    app.config.from_object(
        configurations.get(env, "shhh.config.ProductionConfig"))

    register_extensions(app)

    with app.app_context():
        register_blueprints(app)
        db.create_all()
        try:
            scheduler.start()
        except SchedulerAlreadyRunningError:
            pass
        assets.manifest = False
        assets.cache = False
        try:
            compile_assets(assets)
        except RegisterError:
            pass

        from shhh import views  # pylint: disable=unused-import

    if app.config.get("FORCE_HTTPS"):
        app.before_request(force_https)

    app.after_request(add_security_headers)
    return app
Exemple #3
0
def create_app(env):
    """Application factory."""
    logging.basicConfig(
        level=logging.INFO,
        format="[%(asctime)s] [sev %(levelno)s] [%(levelname)s] [%(name)s]> %(message)s",
        datefmt="%a, %d %b %Y %H:%M:%S",
    )

    if env == EnvConfig.TESTING.value:
        logging.getLogger("shhh").setLevel(logging.CRITICAL)
        logging.getLogger("apscheduler").setLevel(logging.CRITICAL)
        logging.getLogger("tasks").setLevel(logging.CRITICAL)

    app = Flask(__name__)

    configurations = {
        EnvConfig.TESTING.value: "shhh.config.TestConfig",
        EnvConfig.DEV_LOCAL.value: "shhh.config.DefaultConfig",
        EnvConfig.DEV_DOCKER.value: "shhh.config.DockerConfig",
        EnvConfig.HEROKU.value: "shhh.config.HerokuConfig",
        EnvConfig.PRODUCTION.value: "shhh.config.ProductionConfig",
    }
    app.config.from_object(configurations.get(env, "shhh.config.ProductionConfig"))

    register_extensions(app)

    with app.app_context():
        register_blueprints(app)
        db.create_all()
        try:
            scheduler.start()
        except SchedulerAlreadyRunningError:
            pass
        assets.manifest = False
        assets.cache = False
        try:
            compile_assets(assets)
        except RegisterError:
            pass

    app.context_processor(inject_global_vars)
    app.after_request(optimize_response)
    app.after_request(security_headers)

    app.register_error_handler(HTTPStatus.NOT_FOUND.value, not_found_error)
    app.register_error_handler(HTTPStatus.INTERNAL_SERVER_ERROR.value, internal_server_error)

    return app
Exemple #4
0
def create_app(env=os.environ.get("FLASK_ENV")):
    """Application factory."""
    logging.basicConfig(
        level=logging.INFO,
        format=("[%(asctime)s] [sev %(levelno)s] [%(levelname)s] "
                "[%(name)s]> %(message)s"),
        datefmt="%a, %d %b %Y %H:%M:%S",
    )

    #  Disable werkzeug logging under WARNING.
    logging.getLogger("werkzeug").setLevel(logging.WARNING)

    if env == "testing":
        logging.getLogger("shhh").setLevel(logging.CRITICAL)
        logging.getLogger("apscheduler").setLevel(logging.CRITICAL)

    app = Flask(__name__)

    configurations = {
        "dev-local": "shhh.config.DefaultConfig",
        "testing": "shhh.config.TestConfig",
        "dev-docker": "shhh.config.DockerConfig",
        "heroku": "shhh.config.HerokuConfig",
        "production": "shhh.config.ProductionConfig",
    }
    app.config.from_object(
        configurations.get(env, "shhh.config.ProductionConfig"))

    register_extensions(app)

    with app.app_context():
        register_blueprints(app)

        db.create_all()
        scheduler.start()

        assets.manifest = False
        assets.cache = False
        compile_assets(assets)

        from shhh import views  # pylint: disable=unused-import

    return app