示例#1
0
def make_flask():
    flask_app = Flask(__name__)
    flask_app.config["SECRET_KEY"] = str(uuid.uuid4())
    flask_app.config["MAX_CONTENT_LENGTH"] = 8 * 1024 * 1024
    flask_app.url_map.strict_slashes = False
    flask_app.wsgi_app = ProxyFix(flask_app.wsgi_app)

    if "database" in ConfigManager.get_config():
        config_database(flask_app, ConfigManager.get_config_value("database"))

    apis_config = ConfigManager.get_config_value("apis")

    for api_config in apis_config.values():
        api = create_api(api_config)
        api.init_app(flask_app)

    # pylint: disable=unused-variable
    @flask_app.errorhandler(422)
    def handle_error(err):
        headers = err.data.get("headers", None)
        messages = err.data.get("messages", ["Invalid request."])
        if headers:
            return jsonify({"errors": messages}), err.code, headers
        return jsonify({"errors": messages}), err.code

    CORS(flask_app)
    return flask_app
示例#2
0
def make_flask():
    flask_app = Flask(__name__)
    flask_app.config["SECRET_KEY"] = str(uuid.uuid4())
    flask_app.config["MAX_CONTENT_LENGTH"] = 8 * 1024 * 1024

    if "database" in ConfigManager.get_config():
        config_database(flask_app, ConfigManager.get_config_value("database"))

    return flask_app