Reorganize repos
This commit is contained in:
58
app/__init__.py
Normal file
58
app/__init__.py
Normal file
@ -0,0 +1,58 @@
|
||||
from flask import Flask, render_template
|
||||
from werkzeug.exceptions import HTTPException
|
||||
|
||||
from flask_mobility import Mobility
|
||||
from flask_pyoidc.provider_configuration import ProviderConfiguration, ClientMetadata
|
||||
|
||||
|
||||
from . import filters
|
||||
from .lib import OIDCAuthentication
|
||||
import os
|
||||
|
||||
mobility = Mobility()
|
||||
|
||||
auth = OIDCAuthentication()
|
||||
|
||||
|
||||
def create_app(environment='development'):
|
||||
|
||||
from config import config
|
||||
|
||||
# Instantiate app.
|
||||
app_prefix = os.getenv('APPLICATION_ROOT', '')
|
||||
app = Flask(__name__,
|
||||
static_url_path=f"{app_prefix}/static")
|
||||
|
||||
# Set app config.
|
||||
env = os.environ.get('FLASK_ENV', environment)
|
||||
app.config.from_object(config[env])
|
||||
app.config.from_prefixed_env(prefix="HSMAN")
|
||||
config[env].configure(app)
|
||||
app.config['APP_TZ'] = os.environ.get('TZ', 'UTC')
|
||||
|
||||
app.logger.info("middleware init: mobility")
|
||||
mobility.init_app(app)
|
||||
|
||||
app.logger.info("middleware init: auth")
|
||||
auth.init_app(app)
|
||||
|
||||
# Register blueprints.
|
||||
from .views import main_blueprint, rest_blueprint
|
||||
app.logger.info(f"registering main blueprint with prefix '{
|
||||
main_blueprint.url_prefix}'")
|
||||
app.register_blueprint(main_blueprint)
|
||||
|
||||
app.logger.info(f"registering rest blueprint with prefix '{
|
||||
rest_blueprint.url_prefix}'")
|
||||
app.register_blueprint(rest_blueprint)
|
||||
|
||||
app.logger.info("jinja2 custom filters loaded")
|
||||
filters.init_app(app)
|
||||
|
||||
# Error handlers.
|
||||
|
||||
@app.errorhandler(HTTPException)
|
||||
def handle_http_error(exc):
|
||||
return render_template('error.html', error=exc), exc.code
|
||||
|
||||
return app
|
Reference in New Issue
Block a user