Skip to content

How to use tower_http::normalize_path in axum v0.7? #2377

Answered by davidpdrsn
duskmoon314 asked this question in Q&A
Discussion options

You must be logged in to vote

You can use "fully qualified" syntax to call ServiceExt::into_make_service and specific the type parameters:

use axum::{extract::Request, Router, ServiceExt};
use tower::Layer;
use tower_http::normalize_path::NormalizePathLayer;

#[tokio::main]
async fn main() {
    let app = Router::new();

    let app = NormalizePathLayer::trim_trailing_slash().layer(app);

    let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
        .await
        .unwrap();

    axum::serve(listener, ServiceExt::<Request>::into_make_service(app)) // <-- this
        .await
        .unwrap();
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@duskmoon314
Comment options

@timhughes
Comment options

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