Skip to content

Making tower-http's ServeDir fall back to axum::Router #3206

Answered by mladedav
utkarshkukreti asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry, I thought that method was available on the services themselves, not just the builder.

You can do this to force the correct types:

    let app = tower_http::services::ServeDir::new("src")
        .fallback(app.into_service())
        .map_response(|response| response.map(axum::body::Body::new));

Then the code you posted originally compiles.

The into_service call seems like something we should be able to get rid of, but it seems the type inference needs it right now.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@utkarshkukreti
Comment options

@mladedav
Comment options

mladedav Feb 5, 2025
Collaborator

Answer selected by utkarshkukreti
@utkarshkukreti
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants