def _init_routes(self): """Initialize hooks and URI routes to resources.""" catalog = [ ('/v1', v1_0.public_endpoints(self, self._conf)), ('/v1.1', v1_1.public_endpoints(self, self._conf)), ('/v2', v2_0.public_endpoints(self, self._conf)), ('/', [('', version.Resource())]) ] if self._conf.admin_mode: catalog.extend([ ('/v1', v1_0.private_endpoints(self, self._conf)), ('/v1.1', v1_1.private_endpoints(self, self._conf)), ('/v2', v2_0.private_endpoints(self, self._conf)), ]) # NOTE(wanghao): Since hook feature has removed after 1.0.0, using # middleware instead of it, but for the compatibility with old version, # we support them both now. Hook way can be removed after falcon # version must be bigger than 1.0.0 in requirements. if (d_version.LooseVersion(falcon.__version__) >= d_version.LooseVersion("1.0.0")): middleware = [FuncMiddleware(hook) for hook in self.before_hooks] self.app = falcon.API(middleware=middleware) else: self.app = falcon.API(before=self.before_hooks) self.app.add_error_handler(Exception, self._error_handler) for version_path, endpoints in catalog: if endpoints: for route, resource in endpoints: self.app.add_route(version_path + route, resource)
def _init_routes(self): """Initialize hooks and URI routes to resources.""" catalog = [ ('/v1', v1_0.public_endpoints(self, self._conf)), ('/v1.1', v1_1.public_endpoints(self, self._conf)), ('/v2', v2_0.public_endpoints(self, self._conf)), ('/', [('', version.Resource())]) ] if self._conf.admin_mode: catalog.extend([ ('/v1', v1_0.private_endpoints(self, self._conf)), ('/v1.1', v1_1.private_endpoints(self, self._conf)), ('/v2', v2_0.private_endpoints(self, self._conf)), ]) # NOTE(wanghao): Since hook feature has removed after 1.0.0, using # middleware instead of it, but for the compatibility with old version, # we support them both now. Hook way can be removed after falcon # version must be bigger than 1.0.0 in requirements. if LooseVersion(falcon.__version__) >= LooseVersion("1.0.0"): middleware = [FuncMiddleware(hook) for hook in self.before_hooks] self.app = falcon.API(middleware=middleware) else: self.app = falcon.API(before=self.before_hooks) self.app.add_error_handler(Exception, self._error_handler) for version_path, endpoints in catalog: for route, resource in endpoints: self.app.add_route(version_path + route, resource)
def _init_routes(self): """Initialize hooks and URI routes to resources.""" catalog = [ ('/v1', v1_0.public_endpoints(self, self._conf)), ('/v1.1', v1_1.public_endpoints(self, self._conf)), ] if self._conf.admin_mode: catalog.extend([ ('/v1', v1_0.private_endpoints(self, self._conf)), ('/v1.1', v1_1.private_endpoints(self, self._conf)), ]) self.app = falcon.API(before=self.before_hooks) for version_path, endpoints in catalog: for route, resource in endpoints: self.app.add_route(version_path + route, resource)