Beispiel #1
0
def create_app(env="production"):
    app = Flask(__name__)
    init_config(app, env)

    from app.broker import publisher
    publisher.init_app(app)

    from app.celery import celery
    celery.init_app(app)

    from app.database.db import pool, init_db
    init_db(app)

    from app.jwt import init_jwt
    init_jwt(app)

    from app.tarantool.tarantool import init_tarantool
    init_tarantool(app)

    init_routes(app)
    from app.di import configure_di
    injector = FlaskInjector(app=app, modules=[configure_di])
    app.di = injector.injector

    from app.auth import login_manager
    login_manager.init_app(app)

    init_template_filters(app)
    init_tasks()

    from app.service_discovery import init_discovery
    init_discovery(app)

    return app
Beispiel #2
0
def create_app(env=None):
    #
    # Create app instance and load config
    app = Flask(__name__)
    if not env:
        env = app.config['ENV']
    app.config.from_object(configs[env])

    #
    # Initializse flask extensions
    db.init_app(app)
    alembic.init_app(app)
    login_manager.init_app(app)
    login_manager.login_view = 'auth.login'
    assets = Environment(app)

    #
    # Register asset bundles
    css = Bundle('css/bootstrap.min.css', 'css/simplemde.min.css',
                 output='bundle.css')
    assets.register('css_all', css)
    js = Bundle('js/simplemde.min.js', output='bundle.js')
    assets.register('js_all', js)

    #
    # Custom jinja filters
    app.add_template_filter(lambda s: markdown(s), name='markdown')

    #
    # Register routes from blueprints
    app.register_blueprint(auth)
    app.register_blueprint(homepage)
    app.register_blueprint(profile, url_prefix='/profile')

    #
    # Custom cli commands
    @app.cli.command('create-user')
    @click.option('-u', '--username', required=True)
    @click.option('-p', '--password', required=True)
    def create_user(username, password):
        user_repository.create(username, password)
        click.echo('Created user {}'.format(username))

    #
    # GO!
    return app
Beispiel #3
0
def create_app(config_class=Config):
    # Setup flask app and configure from config object
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    app.config.from_object(config_class)

    # Register blueprints
    app.register_blueprint(main_bp)
    app.register_blueprint(auth_bp)
    app.register_blueprint(acc_bp)
    app.register_blueprint(interface_bp, url_prefix='/interface')
    app.register_blueprint(questions_bp, url_prefix='/questions')

    # Initialise objects
    db.init_app(app)
    login_manager.init_app(app)
    migrate.init_app(app, db)

    return app
def create_app(env=None):
    #
    # Create app instance and load config
    app = Flask(__name__)
    if not env:
        env = app.config['ENV']
    app.config.from_object(configs[env])

    #
    # Initialize flask extensions
    db.init_app(app)
    alembic.init_app(app)
    login_manager.init_app(app)
    login_manager.login_view = 'auth.login'

    #
    # Custom jinja filters
    app.add_template_filter(lambda s: markdown(s), name='markdown')

    #
    # Register routes from blueprints
    app.register_blueprint(auth)
    app.register_blueprint(homepage)

    #
    # Custom cli commands
    @app.cli.command('create-user')
    @click.option('-u', '--username', required=True)
    @click.option('-p', '--password', required=True)
    def create_user(username, password):
        user = User(username=username, password=password)
        db.session.add(user)
        db.session.commit()
        click.echo('Created user {}'.format(username))

    #
    # GO!
    return app
Beispiel #5
0
def create_app():
    app = Flask(__name__)

    app.config['SECRET_KEY'] = config.SECRET_KEY
    app.config['SQLALCHEMY_DATABASE_URI'] = config.DATABASE_URI
    app.config['CACHE_TYPE'] = 'simple'
    app.config['CACHE_DEFAULT_TIMEOUT'] = 300
    app.config['NAME'] = config.NAME or 'cd'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    bootstrap = Bootstrap(app)

    app.register_blueprint(admin, url_prefix='/admin')
    app.register_blueprint(console, url_prefix='/console')
    app.register_blueprint(auth, url_prefix='/login')
    app.register_blueprint(home, url_prefix='/')

    database.db.init_app(app)
    login_manager.init_app(app)

    with app.app_context():
        database.db.create_all()
    return app
Beispiel #6
0
from .api.user_routes import user_routes
from .api.session import session
from .api.puzzles import puzzles
from .api.packs import packs

from .config import Config

app = Flask(__name__)

app.config.from_object(Config)
app.register_blueprint(user_routes, url_prefix='/api/users')
app.register_blueprint(session, url_prefix='/api/session')
app.register_blueprint(puzzles, url_prefix='/api/puzzles')
app.register_blueprint(packs, url_prefix='/api/packs')
db.init_app(app)
login_manager.init_app(app)
migrate = Migrate(app, db)

## Application Security
CORS(app)


@app.after_request
def inject_csrf_token(response):
    response.set_cookie(
        'csrf_token',
        generate_csrf(),
        secure=True if os.environ.get('FLASK_ENV') else False,
        samesite='Strict' if os.environ.get('FLASK_ENV') else None,
        httponly=True)
    return response