Example #1
0
def create_app():
    logging.basicConfig(level=logging.DEBUG)

    app = web.Application(middlewares=[
        web_middlewares.normalize_path_middleware(append_slash=True),
    ], client_max_size=4096**2)

    app.update(name='consumer', settings=settings)

    # setup Jinja2 template renderer
    aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader(str(settings.PROJECT_ROOT / 'templates')))

    # get credentials of the correct environment
    for key, value in get_postgres_credentials(settings.ENVIRONMENT)._asdict().items():
        setattr(app['settings'], key, value)

    # create db connection on startup, shutdown on exit
    app.on_startup.append(on_startup)
    app.on_cleanup.append(close_pg)

    # setup views and routes
    setup_routes(app)

    # setup middlewares
    # setup_middlewares(app)

    # setup aiojobs scheduler
    setup_aiojobs(app)

    return app
Example #2
0
def create_app():
    configure_logging(level=CONFIG.log_level)
    api = web.Application()
    api.router.add_routes(routes)
    app = web.Application()
    app.add_subapp('/api/v1', api)
    setup_aiojobs(app, limit=5000, pending_limit=5000)
    return app
Example #3
0
def create_app():

    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('templates'))
    app['static_root_url'] = '/static'
    setup_routes(app)
    setup_aiojobs(app)
    return app
Example #4
0
def create_app():
    configure_logging(level=CONFIG.log_level)
    backdoor.setup()
    if CONFIG.sentry_enable:
        sentry_sdk.init(
            dsn=CONFIG.sentry_dsn,
            integrations=[AioHttpIntegration()]
        )
    api = web.Application()
    api.router.add_routes(routes)
    app = web.Application()
    app.add_subapp('/api/v1', api)
    setup_aiojobs(app, limit=5000, pending_limit=5000)
    return app
def create_app():
    logging.basicConfig(level=logging.DEBUG)

    app = web.Application(middlewares=[
        web_middlewares.normalize_path_middleware(append_slash=True),
    ],
                          client_max_size=4096**2)

    app.update(name='producer', settings=settings)

    # setup Jinja2 template renderer; jinja2 contains various loaders, can also try PackageLoader etc.
    aiohttp_jinja2.setup(app,
                         loader=jinja2.FileSystemLoader(
                             str(settings.PROJECT_ROOT / 'static')))

    # get credentials of the correct environment
    for key, value in get_postgres_credentials(
            settings.ENVIRONMENT)._asdict().items():
        setattr(app['settings'], key, value)

    # create db connection on startup, shutdown on exit
    app.on_startup.append(on_startup)
    app.on_cleanup.append(close_pg)

    # setup views and routes
    setup_routes(app)

    # setup middlewares
    # setup_middlewares(app)

    # setup aiojobs scheduler
    setup_aiojobs(app)

    # Configure default CORS settings.
    cors = aiohttp_cors.setup(app,
                              defaults={
                                  "*":
                                  aiohttp_cors.ResourceOptions(
                                      allow_credentials=True,
                                      expose_headers="*",
                                      allow_headers="*",
                                  )
                              })

    # Configure CORS on all routes.
    for route in list(app.router.routes()):
        cors.add(route)

    return app
Example #6
0
def setup_app(app, config):
    # Setup routers
    app = setup_services(app, config)

    app.add_routes(all_routes)
    app.add_routes([web.static("/assets", "./assets", show_index=True)])

    # not to add static files during CI
    if not os.getenv('GITHUB_ACTIONS'):
        try:
            app.add_routes(
                [web.static("/app", "../wotapp/dist/", show_index=True)])
        except:
            pass

    setup_aiojobs(app)
    setup_cors(app)
    setup_socket_io(app)

    # run after setup_aiojobs
    app.on_startup.append(on_startup)
    app.on_cleanup.append(on_cleanup)

    return app
    logging.debug("Logging started")

# Redis connect
storage, redis_pool = redis_connect(app)
setup(app, storage)

# Create log
create_loggers(app)

# Add routes
apply_routes(app)

#  before
app.middlewares.append(police_middleware)

#  after
app.middlewares.append(errors_middleware)

sio, background_task = get_socket_io_route(sio, app)

app.on_startup.append(init_pg)
app.on_cleanup.append(close_pg)
app.on_cleanup.append(dispose_redis_pool)
sio.start_background_task(background_task)
setup_aiojobs(app)

if __name__ == '__main__':
    web.run_app(app,
                host=os.getenv('HOST', '0.0.0.0'),
                port=os.getenv('PORT', '8080'))