def create_app(): """Instantiates and configures the BFEX application. First, any environment variables needed are retrieved using sensible defaults for a development environment. Next, any initializations that need to be performed are done. Currently, we instantiate a connection to elastic and initialize the model definitions in the database. Finally, API blueprints are registered to the application so they can be accessed. Environment Variables: ELASTIC_HOST: URL of the elasticsearch instance to be used. If undefined, localhost is used. :return An initialized and configured instance of a Flask application. """ from elasticsearch_dsl.connections import connections app = Flask("bfex") # Elasticsearch connection setup elastic_host = os.getenv("ELASTIC_HOST", "localhost") connections.create_connection(hosts=[elastic_host]) initialize_models() app.register_blueprint(faculty_bp) app.register_blueprint(search_bp) app.register_blueprint(batch_bp) app.register_blueprint(workflow_bp) #register_approach(GenericApproach, 0) #register_approach(RakeApproach, 1) #key_generator = KeyGenerator() #key_generator.register_approach(GenericApproach, 0) #key_generator.register_approach(RakeApproach, 1) #app.register_blueprint(data_ingestion) return app
def setup_elastic_connection(request): """Creates a connection to elasticsearch for use in tests. If the environment variable PYTEST_ENV is set, and a connection does not already exist, a new one will be created. Runs before every test. """ if is_dev_env(): return try: connections.get_connection() except KeyError: elastic_host = os.getenv("ELASTIC_HOST", "localhost") connections.create_connection(hosts=[elastic_host]) initialize_models()
def create_app(): """Instantiates and configures the BFEX application. First, any environment variables needed are retrieved using sensible defaults for a development environment. Next, any initializations that need to be performed are done. Currently, we instantiate a connection to elastic and initialize the model definitions in the database. Finally, API blueprints are registered to the application so they can be accessed. Environment Variables: ELASTIC_HOST: URL of the elasticsearch instance to be used. If undefined, localhost is used. :return An initialized and configured instance of a Flask application. """ from elasticsearch_dsl.connections import connections app = Flask("bfex", static_url_path='') cors = CORS(app) app.config['CORS_HEADERS'] = 'Content-Type' @app.route('/static/<path:path>') def send_static(path): return send_from_directory('static', path) # Elasticsearch connection setup elastic_host = os.getenv("ELASTIC_HOST", "localhost") connections.create_connection(hosts=[elastic_host]) initialize_models() app.register_blueprint(faculty_bp) app.register_blueprint(search_bp) app.register_blueprint(batch_bp) app.register_blueprint(workflow_bp) app.register_blueprint(grants_bp) app.register_blueprint(document_bp) app.register_blueprint(keyword_bp) app.register_blueprint(lexicon_bp) return app