tower-rs / tower-http

HTTP specific Tower utilities.
675 stars 156 forks source link

Basic Middleware with Axum failing #442

Closed Naginipython closed 9 months ago

Naginipython commented 9 months ago

Bug Report

Version

tower = { vesion = "0.4.13", features = ["full"] } tower-http = { vesion = "0.5.0", features = ["full"] }

Platform

Manjaro Linux x86_64

Crates

tower-http, tower, axum

Description

I am trying to set up basic middleware, and I am receiving errors.

use axum::{
    routing::get,
    Router,
};
use tower_http::trace::TraceLayer;

pub mod routes;

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/test/hello", get(routes::hello))
        .layer(TraceLayer::new_for_http());

    println!("Server is running on port localhost:3000");
    axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
        .serve(app.into_make_service())
        .await
        .unwrap();
}

The error says the following, on the .layer() line: the trait bound 'Trace<Route<_>, SharedClassifier<ServerErrorsAsFailures>>: Service<axum::http::Request<_>>' is not satisfied the trait 'Service<http::request::Request<ReqBody>>' is implemented for 'Trace<S, M, MakeSpanT, OnRequestT, OnResponseT, OnBodyChunkT, OnEosT, OnFailureT>'

seanmonstar commented 9 months ago

Axum is not ready to depend on tower-http v0.5. Downgrade your requirement to 0.4.