-
SummaryI've been having trouble trying to use I'd love a pointer and suggestions on how to debug this. I didn't see one, but it'd be awesome to have a use std::sync::Arc;
use axum::ServiceExt;
use axum::{Router, extract::State, response::IntoResponse, routing::get};
use tower::ServiceBuilder;
use tower_http::ServiceBuilderExt;
use tower_http::request_id::MakeRequestUuid;
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/", get(root))
.route("/hello", get(hello))
.with_state(Arc::new(AppState {
thing: "buddy".to_string(),
}));
let middleware = ServiceBuilder::new()
.set_x_request_id(MakeRequestUuid)
.layer(tower_http::normalize_path::NormalizePathLayer::trim_trailing_slash())
.propagate_x_request_id();
let app = middleware.layer(app);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app.into_make_service())
.await
.unwrap();
}
struct AppState {
thing: String,
}
async fn root() -> &'static str {
"hey pal"
}
async fn hello(state: State<Arc<AppState>>) -> impl IntoResponse {
format!("hello {thing}", thing = state.thing)
} here's my Cargo.toml [package]
name = "axum-tower-slashes"
version = "0.1.0"
edition = "2024"
[dependencies]
axum = { version = "0.8.4", features = ["json"] }
tokio = { version = "1.45.1", features = ["full"] }
tower = "0.5.2"
tower-http = { version = "0.6.6", features = ["catch-panic", "normalize-path", "request-id", "util"] } The compiler output is fairly inscrutable:
axum version0.8.4 |
Beta Was this translation helpful? Give feedback.
Answered by
mladedav
Jun 3, 2025
Replies: 1 comment 12 replies
-
You need to change |
Beta Was this translation helpful? Give feedback.
12 replies
Answer selected by
jplatte
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to change
let app = middleware.layer(app);
tolet app = middleware.service(app);
.