Ejemplo n.º 1
0
def create_app():
    app = falcon.API(middleware=[CrossDomain(), JSONTranslator()])

    app.add_error_handler(Exception, error_handler)

    setup_routes(app)

    return app
Ejemplo n.º 2
0
def init():
    from app.api import API
    from app.utils.database import db_session, init_session
    from app.middleware import AuthHandler, JSONTranslator, DatabaseSessionManager

    init_session()
    middleware = [
        AuthHandler(),
        JSONTranslator(),
        DatabaseSessionManager(db_session)
    ]
    application = API(middleware=middleware)

    LOG.info('API Server is starting')

    return application
Ejemplo n.º 3
0
def create_app(
):  #Create app function instantiates API object and setup API routes
    try:
        app = falcon.API(middleware=[
            Crossdomain(),
            # AuthMiddleware(),
            JSONTranslator()
        ])  ## Create Falcon API object through which we can add routes
        logger.info('APP started successfully')
        setup_routes(app)  #Adding routes to falcon API
    except Exception as e:
        logger.error('Launching APP failed {}'.format(e))
        raise falcon.HTTPError(
            status="503 APP Unavailable",
            title='Atlantis APP',
            description='Atlantis falcon APP failed to start',
            code=503)
    return app
def create_app():
    app = falcon.API(middleware=[CrossDomain(), JSONTranslator()])

    json_handler = media.JSONHandler(
        dumps=partial(rapidjson.dumps, ensure_ascii=False, sort_keys=True),
        loads=rapidjson.loads,
    )
    extra_handlers = {
        "application/json": json_handler,
    }

    app.req_options.media_handlers.update(extra_handlers)
    app.resp_options.media_handlers.update(extra_handlers)
    app.add_error_handler(Exception, error_handler)

    setup_routes(app)

    return app
Ejemplo n.º 5
0
                       userauth.Collection())
        self.add_route("/app/api/apiv1/create_user", userauth.Collection())
        self.add_route("/app/api/apiv1/create_group", userauth.Collection())
        self.add_route("/app/api/apiv1/update_records", userauth.Collection())
        self.add_route("/app/api/apiv1/delete_records", userauth.Collection())
        self.add_route("/app/api/apiv1/capture_video",
                       videocapture.VideoCapture())
        self.add_route("/app/api/apiv1/stop_video",
                       videocapture.VideoCapture())
        self.add_route("/app/api/apiv1/status", videocapture.VideoCapture())
        self.add_error_handler(AppError, AppError.handle)


init_session()
middleware = [
    JSONTranslator(),
    DatabaseSessionManager(db_session),
    ResponseLogger(),
    RedixDb(),
    CorsMiddleware()
]

application = App(middleware=middleware)
'''def application(env, start_response):
        uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'], env.get('HTTP_ORIGIN', ''))
        uwsgi.websocket_send("Hello world")
        while True:
                msg = uwsgi.websocket_recv()
                uwsgi.websocket_send(msg)'''

if __name__ == "__main__":
Ejemplo n.º 6
0
def client():
    config.DB_AUTOCOMMIT = False

    init_session()
    middleware = [JSONTranslator(), DatabaseSessionManager(db_session)]
    return testing.TestClient(App(middleware=middleware))
Ejemplo n.º 7
0
LOG = log.get_logger()


class App(falcon.API):
    def __init__(self, *args, **kwargs):
        super(App, self).__init__(*args, **kwargs)
        LOG.info("API Server is starting")

        self.add_route("/", base.BaseResource())
        self.add_route("/v1/users", users.Collection())
        self.add_route("/v1/users/{user_id}", users.Item())
        self.add_route("/v1/users/self/login", users.Self())
        self.add_route("/v1/users/info/self", users.UserInformation())
        self.add_route("/v1/users/info", users.AllUserInformation())
        self.add_route("/v1/deploy", deployment.Deployment())

        self.add_error_handler(AppError, AppError.handle)


init_session()
middleware = [AuthHandler(), JSONTranslator(), DatabaseSessionManager(db_session), HandleCORS()]
application = App(middleware=middleware)


if __name__ == "__main__":
    from wsgiref import simple_server

    httpd = simple_server.make_server("127.0.0.1", 5000, application)
    httpd.serve_forever()
Ejemplo n.º 8
0
        self.add_route('/v2/NotificationCount', v2_notification.NotificationCount())
        self.add_route('/v3/Notifications', v2_notification.Notifications())

        # User Information
        self.add_route('/v2/User/PaymentAccount', v2_user.PaymentAccount())
        self.add_route('/v2/User/PersonalInfo', v2_user.PersonalInfo())

        # Statistics
        self.add_route('/v2/Statistics/Token/{contract_address}', v2_statistics.Token())

        """
        Version 3
        """

        # Notifications
        self.add_route('/v3/Notifications', v3_notification.Notifications())
        self.add_route('/v3/Notifications/{id}', v3_notification.NotificationsId())

        """
        Error Handler
        """

        self.add_error_handler(AppError, AppError.handle)


init_session()
middleware = [JSONTranslator(), DatabaseSessionManager(db_session), CORSMiddleware()]
application = App(middleware=middleware)

LOG.info("Service started successfully")