Beispiel #1
0
def serve_files_dynamic(
    router: Router, files_handler: FilesHandler, options: ServeFilesOptions
) -> None:
    """
    Configures a route to serve files dynamically, using the given files handler and
    options.
    """
    options.validate()

    handler = get_files_route_handler(
        files_handler,
        str(options.source_folder),
        options.discovery,
        options.cache_time,
        options.extensions,
        options.root_path,
        options.index_document,
        options.fallback_document,
    )

    if options.allow_anonymous:
        handler = allow_anonymous()(handler)

    route = Route(
        get_static_files_route(options.root_path),
        handler,
    )
    router.add_route("GET", route)
    router.add_route("HEAD", route)
Beispiel #2
0
    def bind_app(self, app: Application) -> None:
        if app.started:
            raise TypeError("The application is already started. "
                            "Use this method before starting the application.")

        for ui_provider in self.ui_providers:
            ui_handler = ui_provider.get_ui_handler()
            ui_handler = self.ignore()(ui_handler)
            ui_handler = allow_anonymous(self.anonymous_access)(ui_handler)
            app.router.add_get(ui_provider.ui_path, ui_handler)

        self.register_docs_handler(app)

        app.after_start += self.build_docs
Beispiel #3
0
def serve_files_dynamic(
    router: Router,
    files_handler: FilesHandler,
    source_folder: str,
    *,
    discovery: bool,
    cache_time: int,
    extensions: Optional[Set[str]],
    root_path: str,
    index_document: Optional[str],
    fallback_document: Optional[str],
    anonymous_access: bool = True,
) -> None:
    """
    Configures a route to serve files dynamically, using the given files handler and
    options.
    """
    validate_source_path(source_folder)

    if not extensions:
        extensions = get_default_extensions()

    handler = get_files_route_handler(
        files_handler,
        str(source_folder),
        bool(discovery),
        int(cache_time),
        set(extensions),
        root_path,
        index_document,
        fallback_document,
    )

    if anonymous_access:
        handler = allow_anonymous()(handler)

    route = Route(
        get_static_files_route(root_path),
        handler,
    )
    router.add_route("GET", route)
    router.add_route("HEAD", route)