Пример #1
0
def make_app():
    http_origins = os.getenv("CORS_URLS",
                             ",".join([
                                      "http://localhost:8081",
                                      ])).split(",")
    ws_origins = [url_to_ws_origins(u) for u in http_origins]

    db_url = orm_utils.heroku_db_url(
        os.getenv('CLEARDB_DATABASE_URL',
                  options.db_url))

    engine = db_connection.register_db(db_url, [Base])
    if options.debug:
        orm_utils.create_all(Base, engine)

    handlers = [
        (r'/websocket', RpcWebsocket, {'ws_origins': ws_origins}),
        (r'/api(.*)', RpcHandler, {'http_origins': http_origins,
                                   'ws_url': 'ws://localhost:8081/websocket' }),
        (r'/logout', LogoutHandler),
        (r'/(.*)', LoginHandler)
    ]

    return tornado.web.Application(
        handlers,
        services=Service.describe(actions),
        broadcast_queue=None,
        template_path=resource_filename('spddo.auth', 'templates'),
        cookie_name='spddo-auth',
        cookie_secret='-it-was-a-dark-and-auth-night-',
        login_url='/api/login',
        micro_context=Context,
        allow_exception_messages=options.debug,
        gzip=True,
        debug=options.debug)
Пример #2
0
def make_app():
    http_origins = options.CORS_URLS
    ws_origins = [url_to_ws_origins(u) for u in http_origins]
    handlers = [
        (r"/api(.*)", RpcHandler, {'http_origins': http_origins,
                                   'ws_url': options.WS_URL}),
        (r"/websocket", RpcWebsocket, {'ws_origins': ws_origins}),
        (r"/logout", LogoutHandler),
        (r"/api.html", ApiPageHandler),
        (r"/", IndexHandler),
    ]

    settings = {
        'services': Service.describe(spddo.micro.func),
        'micro_context': Context,
        'cookie_name': 'micro-session',
        'cookie_secret': '-it-was-a-dark-and-spddo-chat-night-',
        'template_path': resource_filename('spddo.micro', "templates"),
        'allow_exception_messages': options.DEBUG,
        'gzip': True,
        'debug': options.DEBUG
    }

    db_url = heroku_db_url(options.CLEARDB_DATABASE_URL)
    db_connection.db_init(db_url)
    if options.DEBUG:
        create_all(Base, db_connection._engine_)
        with db_connection.session() as session:
            try:
                session.add(model.Person(email="*****@*****.**",
                                         password="******"))
                session.commit()
            except IntegrityError:
                session.rollback()

    if options.PROC_POOL_SIZE:
        pool_init_processes(options.PROC_POOL_SIZE,
                            options.DEBUG)

    if options.CLOUDAMQP_URL:
        queue = PikaTopic(options.CLOUDAMQP_URL,
                          RpcWebsocket.async_broadcast,
                          'micro-chat')
        queue.connect()
        settings["broadcast_queue"] = queue
        logging.info("broadcast_queue %s", options.CLOUDAMQP_URL)

    spddo.micro.func.cache.init_mc()

    return tornado.web.Application(handlers, **settings)
Пример #3
0
def make_app():
    http_origins = os.getenv("CORS_URLS",
                             ",".join([
                                 "http://localhost:8080",
                             ])).split(",")
    ws_origins = [url_to_ws_origins(u) for u in http_origins]

    db_url = orm_utils.heroku_db_url(
        os.getenv('CLEARDB_DATABASE_URL', options.db_url))

    engine = db_connection.register_db(db_url, [Base])
    if options.debug:
        orm_utils.create_all(Base, engine)

    if options.debug:
        site_path = resource_filename('spddo', 'subs')
    else:
        site_path = resource_filename('spddo.subs', 'dist')

    handlers = [
        (r'/websocket', RpcWebsocket, {
            'ws_origins': ws_origins,
            'ws_url': 'ws://localhost:8080/websocket'}),
        (r'/rpc(.*)', RpcHandler, {'http_origins': http_origins}),
        (r'/logout', LogoutHandler),
        (r'/(.*)', tornado.web.StaticFileHandler, {
            'path': site_path,
            'default_filename': 'index.html'
        })
    ]

    micro_pool = ProcessPoolExecutor(3)
    pool_init(micro_pool)
    if options.debug:
        tornado.autoreload.add_reload_hook(micro_pool.shutdown)

    return tornado.web.Application(
        handlers,
        services=Service.describe(actions),
        broadcast_queue=None,
        cookie_name='spddo-mongo',
        cookie_secret='-it-was-a-dark-and-mongo-night-',
        ws_url=os.getenv('ws_url', 'ws://localhost:8080/websocket'),
        login_url='/api/login',
        micro_context=Context,
        allow_exception_messages=options.debug,
        gzip=True,
        debug=options.debug)
Пример #4
0
def make_app():
    http_origins = options.CORS_URLS
    ws_origins = [url_to_ws_origins(u) for u in http_origins]
    handlers = [
        (r"/api(.*)", RpcHandler, {'http_origins': http_origins}),
        (r"/websocket", RpcWebsocket, {'ws_origins': ws_origins}),
        (r"/logout", LogoutHandler),
        (r'/(.*)', tornado.web.StaticFileHandler, {
            'path': resource_filename('spddo.todo', 'web'),
            'default_filename': 'index.html'
        })

    ]

    settings = {
        'services': Service.describe(spddo.todo.actions),
        'micro_context': Context,
        'cookie_name': 'micro-todo-session',
        'cookie_secret': '-it-was-a-dark-and-spddo-todo-night-',
        'allow_exception_messages': options.DEBUG,
        'gzip': True,
        'debug': options.DEBUG
    }

    db_url = heroku_db_url(options.CLEARDB_DATABASE_URL)
    engine = db_connection.db_init(db_url)
    if options.DEBUG:
        create_all(Base, engine)

    if options.PROC_POOL_SIZE:
        pool_init_processes(options.PROC_POOL_SIZE,
                            options.DEBUG)

    if options.CLOUDAMQP_URL:
        queue = PikaTopic(options.CLOUDAMQP_URL,
                          RpcWebsocket.async_broadcast,
                          'micro-chat')
        queue.connect()
        settings["broadcast_queue"] = queue
        logging.info("broadcast_queue %s", options.CLOUDAMQP_URL)

    return tornado.web.Application(handlers,
                                   **settings)
Пример #5
0
def make_app():
    logging.info(get_ws_origins_env())

    db_url = orm_utils.heroku_db_url(options.CLEARDB_DATABASE_URL)
    engine = db_connection.db_init(db_url)

    if options.DEBUG:
        orm_utils.create_all(orm_utils.Base, engine)

    if options.POOL_SIZE:
        micro_pool = ProcessPoolExecutor(options.POOL_SIZE)
        executor.pool_init(micro_pool)
        if options.DEBUG:
            add_reload_hook(micro_pool.shutdown)

    logging.info('Pool size: {}'.format(options.POOL_SIZE))

    request_handlers = [
        (r"/control(.*)", RpcHandler, {
            'http_origins': options.ORIGINS,
            'js_template': "api-tmpl.js",
            'ws_url': options.WS_URL
        }),
        (r"/websocket/?", RpcWebsocket, {
            'ws_origins': get_ws_origins_env()
        }),
    ]

    return Application(
        request_handlers,
        services=Service.describe(actions),
        micro_context=Context,
        template_path=resource_filename('dogooder', 'templates'),
        debug=options.DEBUG,
        allow_exception_messages=options.DEBUG,
        cookie_name=options.COOKIE_NAME,
        cookie_secret=options.COOKIE_SECRET,
        gzip=True,
    )
Пример #6
0
def get_db_url_env():
    db_url = os.getenv('CLEARDB_DATABASE_URL')
    if not db_url:
        raise ValueError('Requires CLEARDB_DATABASE_URL environment variable')
    return heroku_db_url(db_url)