def create_app(env):
    app = Flask(__name__)
    #
    app.config.from_object(envs.get(env))
    init_ext(app)
    init_blue(app)
    init_api(app)
    return app
Beispiel #2
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(environments.get('develop'))
    init_ext(app)
    init_views(app)
    init_api(app)

    return app
Beispiel #3
0
def create_app(profile="default"):
    app = Flask(__name__, template_folder="templates/")

    app.config.from_object(config[profile])
    config[profile].init_app(app)
    app.config.from_envvar("AUTH_SETTINGS", silent=True)

    app.logger.setLevel(logging.DEBUG)

    try:
        logfile = os.path.join(app.config["LOGPATH"], "anmeldesystem.log")
        loghandler = logging.handlers.RotatingFileHandler(logfile,
                                                          maxBytes=10**4,
                                                          backupCount=4)
        loghandler.setLevel(logging.WARNING)
        app.logger.addHandler(loghandler)
    except:
        pass

    from app.db import db

    db.init_app(app)
    db.app = app
    app.db = db

    mail = Mail(app)
    app.mail = mail

    # Set up sanity checks.
    from . import sanity

    app.sanity_check_modules = [sanity]

    from flask_bootstrap import Bootstrap

    Bootstrap(app)

    from app.user import user_blueprint, init_app as init_user

    app.register_blueprint(user_blueprint)
    init_user(app)

    from app.oauth2 import oauth2_blueprint, init_app as init_oauth2

    app.register_blueprint(oauth2_blueprint)
    init_oauth2(app)

    from app.api import api_blueprint, init_app as init_api

    app.register_blueprint(api_blueprint)
    init_api(app)

    from app.registration import registration_blueprint, init_app as init_reg

    app.register_blueprint(registration_blueprint)
    init_reg(app)

    return app
Beispiel #4
0
def create_app(current_config):
    app = Flask(__name__)
    logging.basicConfig(level=current_config.LOG_LEVEL)  # 日志
    app.logger.info(f"current_config: {current_config.__name__}")

    app.config.from_object(current_config)

    # 允许 /api/ 下的 api 跨域访问
    cors.init_app(
        app,
        resources={
            r"/api/*": {
                "origins": "*",
                "max_age": timedelta(days=1),
                "supports_credentials": True,  # 允许跨域使用 cookie
            }
        })

    # 将各 flask 插件注册到 app
    db.init_app(app)
    migrate.init_app(app, db)
    login_manager.init_app(app)
    mail.init_app(app)
    sockets.init_app(app)
    api_rest.init_app(app)

    # ip 访问频率限制
    # 1. 如果 flask 跑在 proxy server 后面(比如 nginx),就需要用 ProxyFix
    # app.wsgi_app = ProxyFix(app.wsgi_app, num_proxies=1)
    limiter.init_app(app)
    for handler in app.logger.handlers:  # 为 limiter 添加日志处理器
        limiter.logger.addHandler(handler)

    # TODO elasticsearch 模糊搜索
    # app.elasticsearch = Elasticsearch([app.config['ELASTICSEARCH_URL']]) \
    #     if app.config['ELASTICSEARCH_URL'] else None

    redis.init_app(app, config_prefix="REDIS0")  # 使用 REDIS0_URL

    # TODO 使用 rq 实现异步任务
    rq.init_app(app)

    # 注册 rest api 模块,
    from app import api as api_v1
    api_v1.init_api(api_rest)  # 注意是使用已经在 app 上注册了的 app_rest

    # Import Sockets events so that they are registered with Flask-Sockets
    from . import events
    events.init_websockets(sockets)

    app.logger.info('拆小鹤后台系统开始启动~ hhh')
    return app
def create_app():
    app = Flask(__name__)

    CORS(app)

    init_api(app)

    # shell context for flask cli
    @app.shell_context_processor
    def ctx():
        return {'app': app, 'db': db}

    return app
Beispiel #6
0
def create_app(config_file, async_mode):
    app = Flask(__name__)
    app.config.from_object(config_file)

    from app.models import db
    db.init_app(app)

    from app.sio import socketIO, init_sockets
    init_sockets()
    socketIO.init_app(app, async_mode=async_mode)

    from app.api import init_api
    init_api(app)

    run_backend_thread(app, socketIO)
    return app
Beispiel #7
0
def create_app(config: object):
    """
    Flask application를 초기화 하고 그 인스턴스를 리턴한다.
    :param config:
    :return: Flask application instance
    """
    logger.debug("=== Flask application start ===")
    flask_app = Flask(__name__)
    __init_config(flask_app, config)
    __init_request_log_handler(flask_app)
    __init_error_handler(flask_app)
    api = init_api()
    flask_app.register_blueprint(api, url_prefix='/api')

    return flask_app
Beispiel #8
0
# -*- coding: utf-8 -*-
from flask import request
from app import create_app
from app.api import init_api

app = create_app()
init_api(app)


@app.after_request
def update_response(response):
    response.headers['Access-Control-Allow-Origin'] = request.environ.get('HTTP_ORIGIN')
    response.headers['Access-Control-Allow-Credentials'] = 'true'
    response.headers[
        'Access-Control-Allow-Headers'] = 'Content-Type, Authorization, Accept, Range, Origin, X-Requested-With'
    response.headers['Access-Control-Allow-Methods'] = 'GET, PUT, POST, DELETE, HEAD'
    response.headers['Cache-Control'] = 'no-store'
    return response


if __name__ == '__main__':
    app.run(port=8077)