Skip to content

tower_http::ServeDir no longer compatible with axum 0.7 #2416

@slatian

Description

@slatian
  • I have looked for existing issues (including closed) about this

Bug Report

In previous versions (0.6 series) of axum one could use the very useful tower_http::ServeDir with an axum Router (other types are affected as well), simply by adding it as a service.

let app = Router::new()
    .route("/", get(handle_default_route))
    .fallback_service(
        ServeDir::new(static_file_directory)
            .fallback(not_found_handler.with_state(shared_state.clone()))
    )

This no longer works because (I aassume) the responses are now Response<Body> instead of being able to be a Response<UnsyncBoxBody<Bytes, BoxError> which is still used by the tower_http.

breaking: The following types/traits are no longer generic over the request body
(i.e. the B type param has been removed) (#1751 and #1789):
[…]

I have not seen anyone solve this for axum 0.7 and was unable to solve this myself.

Maybe there is a simple solution in which case official documentation on how to make this work again would be nice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions