How to use the crossbar.twisted.resource.Resource404 function in crossbar

To help you get started, we’ve selected a few crossbar examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github crossbario / crossbar / crossbar / worker / router.py View on Github external
def _create_web_factory(self, config):

        options = config.get('options', {})

        # create Twisted Web root resource
        if '/' in config['paths']:
            root_config = config['paths']['/']
            root = self._create_resource(root_config, nested=False)
        else:
            root = Resource404(self._templates, b'')

        # create Twisted Web resources on all non-root paths configured
        self._add_paths(root, config.get('paths', {}))

        # create the actual transport factory
        transport_factory = Site(root)
        transport_factory.noisy = False

        # Web access logging
        if not options.get('access_log', False):
            transport_factory.log = lambda _: None

        # Traceback rendering
        transport_factory.displayTracebacks = options.get('display_tracebacks', False)

        # HSTS
github crossbario / crossbar / crossbar / worker / router.py View on Github external
# JSON value resource
        #
        elif path_config['type'] == 'json':
            value = path_config['value']

            return JsonResource(value)

        # CGI script resource
        #
        elif path_config['type'] == 'cgi':

            cgi_processor = path_config['processor']
            cgi_directory = os.path.abspath(os.path.join(self.config.extra.cbdir, path_config['directory']))
            cgi_directory = cgi_directory.encode('ascii', 'ignore')  # http://stackoverflow.com/a/20433918/884770

            return CgiDirectory(cgi_directory, cgi_processor, Resource404(self._templates, cgi_directory))

        # WAMP-Longpoll transport resource
        #
        elif path_config['type'] == 'longpoll':

            path_options = path_config.get('options', {})

            lp_resource = WampLongPollResource(self._router_session_factory,
                                               timeout=path_options.get('request_timeout', 10),
                                               killAfter=path_options.get('session_timeout', 30),
                                               queueLimitBytes=path_options.get('queue_limit_bytes', 128 * 1024),
                                               queueLimitMessages=path_options.get('queue_limit_messages', 100),
                                               debug_transport_id=path_options.get('debug_transport_id', None)
                                               )
            lp_resource._templates = self._templates
github crossbario / crossbar / crossbar / worker / transport / resource.py View on Github external
# JSON value resource
    #
    elif path_config['type'] == 'json':
        value = path_config['value']

        return JsonResource(value)

    # CGI script resource
    #
    elif path_config['type'] == 'cgi':

        cgi_processor = path_config['processor']
        cgi_directory = os.path.abspath(os.path.join(cbdir, path_config['directory']))
        cgi_directory = cgi_directory.encode('ascii', 'ignore')  # http://stackoverflow.com/a/20433918/884770

        return CgiDirectory(cgi_directory, cgi_processor, Resource404(templates, cgi_directory))

    # WAMP-Longpoll transport resource
    #
    elif path_config['type'] == 'longpoll':

        path_options = path_config.get('options', {})

        lp_resource = WampLongPollResource(_router_session_factory,
                                           timeout=path_options.get('request_timeout', 10),
                                           killAfter=path_options.get('session_timeout', 30),
                                           queueLimitBytes=path_options.get('queue_limit_bytes', 128 * 1024),
                                           queueLimitMessages=path_options.get('queue_limit_messages', 100),
                                           debug_transport_id=path_options.get('debug_transport_id', None)
                                           )
        lp_resource._templates = templates
github crossbario / crossbar / crossbar / worker / transport / resource.py View on Github external
cache_timeout = static_options.get('cache_timeout', DEFAULT_CACHE_TIMEOUT)
        allow_cross_origin = static_options.get('allow_cross_origin', True)

        static_resource = static_resource_class(static_dir, cache_timeout=cache_timeout, allow_cross_origin=allow_cross_origin)

        # set extra MIME types
        #
        static_resource.contentTypes.update(EXTRA_MIME_TYPES)
        if 'mime_types' in static_options:
            static_resource.contentTypes.update(static_options['mime_types'])
        patchFileContentTypes(static_resource)

        # render 404 page on any concrete path not found
        #
        static_resource.childNotFound = Resource404(templates, static_dir)

        return static_resource

    # WSGI resource
    #
    elif path_config['type'] == 'wsgi':

        if not _HAS_WSGI:
            raise ApplicationError(u"crossbar.error.invalid_configuration", "WSGI unsupported")

        if 'module' not in path_config:
            raise ApplicationError(u"crossbar.error.invalid_configuration", "missing WSGI app module")

        if 'object' not in path_config:
            raise ApplicationError(u"crossbar.error.invalid_configuration", "missing WSGI app object")
github crossbario / crossbar / crossbar / worker / router.py View on Github external
realm_id = self.realm_to_id[realm]

            realm_schemas = self.realms[realm_id].session._schemas

            return SchemaDocResource(self._templates, realm, realm_schemas)

        # Nested subpath resource
        #
        elif path_config['type'] == 'path':

            nested_paths = path_config.get('paths', {})

            if '/' in nested_paths:
                nested_resource = self._create_resource(nested_paths['/'])
            else:
                nested_resource = Resource404(self._templates, b'')

            # nest subpaths under the current entry
            #
            self._add_paths(nested_resource, nested_paths)

            return nested_resource

        else:
            raise ApplicationError(u"crossbar.error.invalid_configuration",
                                   "invalid Web path type '{}' in {} config".format(path_config['type'],
                                                                                    'nested' if nested else 'root'))
github crossbario / crossbar / crossbar / worker / router.py View on Github external
cache_timeout = static_options.get('cache_timeout', DEFAULT_CACHE_TIMEOUT)
            allow_cross_origin = static_options.get('allow_cross_origin', True)

            static_resource = static_resource_class(static_dir, cache_timeout=cache_timeout, allow_cross_origin=allow_cross_origin)

            # set extra MIME types
            #
            static_resource.contentTypes.update(EXTRA_MIME_TYPES)
            if 'mime_types' in static_options:
                static_resource.contentTypes.update(static_options['mime_types'])
            patchFileContentTypes(static_resource)

            # render 404 page on any concrete path not found
            #
            static_resource.childNotFound = Resource404(self._templates, static_dir)

            return static_resource

        # WSGI resource
        #
        elif path_config['type'] == 'wsgi':

            if not _HAS_WSGI:
                raise ApplicationError(u"crossbar.error.invalid_configuration", "WSGI unsupported")

            if 'module' not in path_config:
                raise ApplicationError(u"crossbar.error.invalid_configuration", "missing WSGI app module")

            if 'object' not in path_config:
                raise ApplicationError(u"crossbar.error.invalid_configuration", "missing WSGI app object")
github crossbario / crossbar / crossbar / worker / transport / resource.py View on Github external
realm_id = node.realm_to_id[realm]

        realm_schemas = node.realms[realm_id].session._schemas

        return SchemaDocResource(templates, realm, realm_schemas)

    # Nested subpath resource
    #
    elif path_config['type'] == 'path':

        nested_paths = path_config.get('paths', {})

        if '/' in nested_paths:
            nested_resource = personality.create_web_service(personality, reactor, nested_paths['/'], templates, cbdir)
        else:
            nested_resource = Resource404(templates, b'')

        # nest subpaths under the current entry
        #
        personality.add_web_services(personality, reactor, nested_resource, nested_paths, templates, log, cbdir, _router_session_factory, node)

        return nested_resource

    elif path_config['type'] in ignore:
        pass

    else:
        raise ApplicationError(u"crossbar.error.invalid_configuration",
                               "invalid Web path type '{}' in {} config".format(path_config['type'],
                                                                                'nested' if nested else 'root'))