async def init_app(config, loop): app = web.Application() app['config'] = config app['websockets'] = {} app.on_shutdown.append(shutdown) db_pool = await init_db(app) mysql_pool = await setup_mysql(app, loop) mongo_pool = await setup_mongo(app, loop) redis_pool = await setup_redis(app) ws_handler = WsHandler(redis_pool, mongo_pool, mysql_pool) setup_routes(app, ws_handler) setup_session(app, RedisStorage(redis_pool)) # needs to be after session setup because of `current_user_ctx_processor` aiohttp_jinja2.setup( app, loader=jinja2.PackageLoader(PACKAGE_NAME), context_processors=[current_user_ctx_processor], ) setup_security(app, SessionIdentityPolicy(), DBAuthorizationPolicy(db_pool)) return app
def main(): app = web.Application() cors = aiohttp_cors.setup(app) cors.add( app.router.add_route("POST", "/get_data", get_data), { "*": aiohttp_cors.ResourceOptions( allow_credentials=True, expose_headers="*", allow_headers="*"), }, ) cors.add( app.router.add_route("POST", "/get_cord", get_coordinates), { "*": aiohttp_cors.ResourceOptions( allow_credentials=True, expose_headers="*", allow_headers="*"), }, ) cors.add( app.router.add_route("POST", "/get_type_heatmap", get_districts), { "*": aiohttp_cors.ResourceOptions( allow_credentials=True, expose_headers="*", allow_headers="*"), }, ) setup_routes(app) web.run_app(app, host="0.0.0.0", port=8000)
async def init_app(): setup_logging() app = web.Application() app['config'] = CONFIG() setup_routes(app) setup_middlewares(app) return app
def init(loop): # setup application and extensions app = web.Application(loop=loop) # setup views and routes setup_routes(app) return app
async def create_app() -> (web.Application, str, str): app = web.Application() setup_routes(app) setup_cache(app) setup_cleanup_ctx(app, [init_jinja, init_web_client]) return app
def create_app() -> web.Application: app = web.Application() setup_routes(app) app.on_startup.append(startup) app.on_shutdown.append(shutdown) setup_aiohttp_apispec(app, swagger_path="/docs") app.middlewares.append(validation_middleware) return app
async def create_app(): app = web.Application(middlewares=[auth_middleware, auth_admin_middleware]) app.router.add_static('/static/', path='app/static/') aiohttp_jinja2.setup(app, loader=jinja2.PackageLoader('app', 'templates')) setup_routes(app) app.on_startup.append(connect_postgres) app.on_cleanup.append(close_postgres) return app
def create_app(debug: bool = False) -> web.Application: """Init application""" app = web.Application(debug=debug) load_config(app) setup_routes(app) app.cleanup_ctx.append(init_pg) return app
async def init_app(): app = web.Application() app.on_startup.append(init_pg) app.on_cleanup.append(close_pg) setup_routes(app) setup_middlewares(app) return app
async def init(loop): app = web.Application(loop=loop) handler = MainHandler() setup_routes(app, handler) host, port = config['host'], config['port'] return app, host, port
async def get_app(db_access_vars, debug): app = web.Application(debug=debug) app = await add_connection_pool(app, db_access_vars) setup_routes(app) if debug: aiohttp_debugtoolbar.setup(app) return app
async def init_app(): app = web.Application() app['config'] = config aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader( str(BASE_DIR / 'app' / 'templates'))) app.on_startup.append(init_pg) app.on_cleanup.append(close_pg) setup_routes(app) return app
def main(): app = web.Application() app['config'] = config aiohttp_jinja2.setup(app, loader=jinja2.PackageLoader('app', 'templates')) app.on_startup.append(startup) app.on_shutdown.append(shutdown) setup_routes(app) web.run_app(app)
async def create_app() -> Application: """Инициализация приложения.""" app = Application() aiohttp_jinja2.setup( app, enable_async=True, loader=jinja2.FileSystemLoader(config.TEMPLATES_PATH), ) setup_sessions(app, EncryptedCookieStorage(config.SECRET_KEY)) setup_routes(app) setup_security(app) setup_custom_middlewares(app) setup_db(app) return app
def create_app(): app = Sanic(__name__) app.config.DB_URL = os.environ['DATABASE_URL'] setup_database(app) setup_routes(app) parameters = { 'host': '0.0.0.0', 'port': int(os.environ.get('APP_PORT', 8000)), 'debug': os.environ.get('APP_DEBUG', 'False').lower() == 'true' } workers = os.environ.get('APP_WORKERS', None) if workers: parameters['workers'] = workers app.run(**parameters)
async def init_app(argv=None): app = web.Application() config = get_config(argv) app['config'] = config # create db connection on startup, shutdown on exit app.on_startup.append(init_pg) app.on_cleanup.append(close_pg) app['event_bus'] = EventBus() # setup views and routes setup_routes(app) setup_subapps(app) return app
def create_app(loop): app = web.Application(loop=loop) app['project_root'] = PROJ_ROOT app['templates_root'] = TEMPLATES_ROOT aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader(str(TEMPLATES_ROOT))) setup_config(app) app.on_startup.append(init_app) app.on_cleanup.append(close_app) setup_routes(app) return app
async def init(loop, events_queue): cfg = get_config() app = web.Application(loop=loop) app["loop"] = loop app["jobs"] = [] app["cfg"] = cfg app["session"] = ClientSession( loop=loop, json_serialize=ujson.dumps ) # TODO: можно полностью поместить только в телебота app["telebot"] = Telebot(cfg.URL, app["session"]) app["games"] = dict() app["events"] = events_queue app["events"].register_observer(CommandsObserver(app)) # await app["events"].set_application(app) setup_routes(app) app.on_cleanup.append(shutdown) return app
async def start_web_app(loop): # setup application and extensions app = web.Application(loop=loop) app.conf = CONFIG app.db_pool = await sql.pool_connection(loop, CONFIG['postgres']) app.redis = await sql.redis_connection(loop, CONFIG['redis']) app.on_cleanup.append(on_cleanup) from app.routes import setup_routes setup_routes(app) aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader( CONFIG['template_dir'])) return app, CONFIG['host'], CONFIG['port']
def create_app(config=None) -> web.Application: app = web.Application() app["config"] = get_config(config) app["project_root"] = pathlib.Path(__file__).parent.as_posix() # setup aiohttp-debugtoolbar aiohttp_debugtoolbar.setup( app, intercept_redirects=False, check_host=False, extra_templates="/usr/src/app/_dev/extra_tpl", extra_panels=[RequestPgDebugPanel, RequestRedisDebugPanel], ) # setup Jinja2 template renderer aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader("./app/templates/")) # create db connection on startup, shutdown on exit app.on_startup.append(setup_redis) app.on_cleanup.append(teardown_redis) # create db connection on startup, shutdown on exit app.on_startup.append(setup_pg) app.on_cleanup.append(teardown_pg) # shutdown SQLalchemy db connection on exit app.on_cleanup.append(teardown_pgsa) # create session on startup, shutdown on exit app.on_startup.append(setup_session) app.on_cleanup.append(teardown_session) # create security using SQLalchemy db connection on startup app.on_startup.append(setup_security) # setup middlewares app.on_startup.append(setup_middlewares) setup_routes(app) return app
def create_app(): app = Flask(__name__) app.config.from_object('config') setup_routes(app) db.init_app(app) migrate.init_app(app, db) cors.init_app(app, resources={ r'/rsa/api/*': { 'origins': '*' }, r'/cesar/api/*': { 'origins': '*' }, r'/vigenere/api/*': { 'origins': '*' }, }) return app
def make_app() -> web.Application: app = web.Application() app.on_startup.append(create_aiopg) app.on_startup.append(setup_cognito_keys) setup_routes(app) cors = aiohttp_cors.setup( app, defaults={ "https://frontoffice.app": 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
async def init(loop): # setup application and extensions app = web.Application(loop=loop) setattr(app, "config", configuration) # configure jinja 2 rendering engine aiohttp_jinja2.setup(app, loader=jinja2.PackageLoader("app", "templates")) setup_global_helpers(app) await bootstrap_dal(configuration, loop) # setup routes setup_routes(app, PROJ_ROOT) # setup middlewares app.middlewares.append(cookies_middleware) app.middlewares.append(errors_middleware) host, port = configuration.host, configuration.port return app, host, port
async def init(loop): cfg = get_config() app = web.Application(loop=loop) app["loop"] = loop app["jobs"] = [] app["cfg"] = cfg app["session"] = ClientSession( loop=loop, json_serialize=ujson.dumps ) # TODO: можно полностью поместить только в телебота app.telebot = Telebot(cfg.URL, app["session"]) app.pool = await aiomysql.create_pool(host=app["cfg"].MYSQL_HOST, port=app["cfg"].MYSQL_PORT, user=app["cfg"].MYSQL_USER, password=app["cfg"].MYSQL_PASS, db=app["cfg"].MYSQL_DBNM, loop=app["loop"], autocommit=True) setup_routes(app) app.on_cleanup.append(shutdown) return app
async def create_app(dev=True): app = web.Application() app['config'] = Config app['dev'] = dev db.init_app(app, {'dsn': Config.DATABASE_URI}) app.middlewares.append(db) app.middlewares.append(error_middleware) app.middlewares.append(validation_middleware) app.middlewares.append(auth_middleware) setup_routes(app) setup_aiohttp_apispec(app, swagger_path="/api/docs") app.on_startup.append(on_startup) app.on_cleanup.append(on_cleanup) setup_log(app) return app
def create_app() -> Flask: new_app = Flask(__name__) # Load configuration settings if app_env == 'production': new_app.config.from_object('app.config.ProductionConfig') elif app_env == 'development': new_app.config.from_object('app.config.DevelopmentConfig') else: print('Unknown ENVIRONMENT variable, loading development configurations.') new_app.config.from_object('app.config.DevelopmentConfig') # Setup database setup_database(new_app) # Setup routes setup_routes(new_app) _ = Bootstrap(new_app) new_app.logger.info('Application initialized.') return new_app
def create_app(loop): # Create base web application app = web.Application() # Settings settings = Settings() # Setup web application paths app.update( name='amiller.im', settings=settings, # path_to_app_root=APP_DIR, path_to_templates=TEMPLATE_DIR, path_to_static=STATIC_DIR, # # blogs=setup_blogs(STATIC_DIR), galleries=setup_galleries(STATIC_DIR), # deployment_time='{:%b, %d %Y %H:%M:%S}'.format(datetime.date.today())) # Template Engine aiohttp_jinja2.setup(app, context_processors=[aiohttp_jinja2.request_processor], loader=jinja2.FileSystemLoader(TEMPLATE_DIR)) # Pre and Post Application Hooks app.on_startup.append(on_startup) app.on_cleanup.append(on_cleanup) # Sessions secret_key = base64.urlsafe_b64decode(settings.COOKIE_SECRET) aiohttp_session.setup(app, EncryptedCookieStorage(secret_key)) # Routes setup_routes(app=app, handler=Handlers) return app
def create_app(config: dict) -> web.Application: app = web.Application() app["config"] = config setup_routes(app) setup_aiohttp_apispec( app, title="YoPay Pay System", version=__version__, info={"description": get_description()}, securityDefinitions={ "auth": {"type": "apiKey", "name": "Authorization", "in": "header"}, "status-manager": { "type": "apiKey", "name": "X-Status-Manager-Token", "in": "header", }, }, tags=[ {"name": "auth", "description": "Registration and authorization"}, {"name": "wallet", "description": "Wallet management methods"}, {"name": "reports", "description": "Reports generating"}, {"name": "operations", "description": "Moving operations between statuses"}, ], ) app.on_startup.extend([swagger, init_postgres, init_redis]) app.on_cleanup.extend([close_redis, close_postgres]) app.middlewares.extend([validation_middleware]) RatesClient.register_app(app) load_private_key(app) return app
from flask_migrate import Migrate from app.routes import setup_routes from app import create_app, db app = create_app() migrate = Migrate(app, db) setup_routes(app) if __name__ == "__main__": app.run(debug=False)
def cli(loop, aiohttp_client): app = web.Application() setup_routes(app) return loop.run_until_complete(aiohttp_client(app))