<reponame>flaxandteal/dp-conceptual-search<gh_stars>1-10
"""
Code for creating HTTP api app
"""
import asyncio
import uvloop
import logging

from dp4py_sanic.app.exceptions.error_handlers import ErrorHandlers

from dp_conceptual_search.config import CONFIG
from dp_conceptual_search.app.search_app import SearchApp

# Import blueprints
from dp_conceptual_search.api.search.routes import search_blueprint
from dp_conceptual_search.api.search.conceptual.routes import conceptual_search_blueprint
from dp_conceptual_search.api.recommend.routes import recommend_blueprint
from dp_conceptual_search.api.spellcheck.routes import spell_check_blueprint
from dp_conceptual_search.api.healthcheck.routes import healthcheck_blueprint


def create_app() -> SearchApp:
    """
    Creates the Sanic APP and registers all blueprints
    :return:
    """
    # First, set the ioloop event policy to use uvloop
    asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

    # Set elasticsearch log level
    logging.getLogger('elasticsearch').setLevel(CONFIG.ELASTIC_SEARCH.elasticsearch_log_level)

    # Now initialise the APP config, logger and ONSRequest handler
    app = SearchApp(CONFIG.APP.title)

    logging.info("Using config", extra={"config": CONFIG.to_dict()})

    # Register blueprints
    app.blueprint(search_blueprint)
    app.blueprint(spell_check_blueprint)
    app.blueprint(healthcheck_blueprint)

    # Enable conceptual search routes?
    if CONFIG.API.conceptual_search_enabled:
        app.blueprint(conceptual_search_blueprint)

    if CONFIG.API.recommended_search_enabled:
        app.blueprint(recommend_blueprint)

    # Register error handlers
    ErrorHandlers.register(app)

    return app

"""
Code for creating HTTP api app
"""
import asyncio
import uvloop
import logging

from dp4py_sanic.app.exceptions.error_handlers import ErrorHandlers

from dp_conceptual_search.config import CONFIG
from dp_conceptual_search.app.search_app import SearchApp

# Import blueprints
from dp_conceptual_search.api.search.routes import search_blueprint
from dp_conceptual_search.api.search.conceptual.routes import conceptual_search_blueprint
from dp_conceptual_search.api.recommend.routes import recommend_blueprint
from dp_conceptual_search.api.spellcheck.routes import spell_check_blueprint
from dp_conceptual_search.api.healthcheck.routes import healthcheck_blueprint


def create_app() -> SearchApp:
    """
    Creates the Sanic APP and registers all blueprints
    :return:
    """
    # First, set the ioloop event policy to use uvloop
    asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

    # Set elasticsearch log level
    logging.getLogger('elasticsearch').setLevel(CONFIG.ELASTIC_SEARCH.elasticsearch_log_level)

    # Now initialise the APP config, logger and ONSRequest handler
    app = SearchApp(CONFIG.APP.title)

    logging.info("Using config", extra={"config": CONFIG.to_dict()})

    # Register blueprints
    app.blueprint(search_blueprint)
    app.blueprint(spell_check_blueprint)
    app.blueprint(healthcheck_blueprint)

    # Enable conceptual search routes?
    if CONFIG.API.conceptual_search_enabled:
        app.blueprint(conceptual_search_blueprint)

    if CONFIG.API.recommended_search_enabled:
        app.blueprint(recommend_blueprint)

    # Register error handlers
    ErrorHandlers.register(app)

    return app
Code for creating HTTP api app # Import blueprints Creates the Sanic APP and registers all blueprints     :return: # First, set the ioloop event policy to use uvloop # Set elasticsearch log level # Now initialise the APP config, logger and ONSRequest handler # Register blueprints # Enable conceptual search routes? # Register error handlers