예제 #1
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)
예제 #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}),
        (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)