diff options
author | Adam T. Carpenter <atc@53hor.net> | 2024-09-28 09:55:53 -0400 |
---|---|---|
committer | Adam T. Carpenter <atc@53hor.net> | 2024-09-28 09:55:53 -0400 |
commit | d1c9f549d3a45118f0a563ddbe07c18fbc8ab660 (patch) | |
tree | 05c27b0976bc359bf512d798376b59269fd64fa3 | |
parent | 45a658e693ab9779ddd364d2acb651178db2dc99 (diff) | |
download | carpentertutoring-blog.tar.xz carpentertutoring-blog.zip |
fix: real fix for trailing backslash handlingblog
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/main.rs | 11 |
2 files changed, 6 insertions, 7 deletions
@@ -12,6 +12,6 @@ axum = "0.7.5" chrono = { version = "0.4.38", default-features = false, features = ["now"] } tokio = { version = "1.40.0", features = ["full"] } tower = "0.5.0" -tower-http = { version = "0.5.2", features = ["fs", "trace"] } +tower-http = { version = "0.5.2", features = ["fs", "trace", "normalize-path"] } tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } diff --git a/src/main.rs b/src/main.rs index b65a58b..252588d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,8 @@ +use tower::Layer; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; -use tower_http::trace::{self, TraceLayer}; +use tower_http::{trace::{self, TraceLayer}, normalize_path::NormalizePathLayer}; use tracing::{info, Level}; -use axum::{routing::get, Router}; +use axum::{routing::get, Router, ServiceExt, extract::Request}; use tutors::fs_tutor_repo::FsTutorRepo; use std::{sync::Arc, env}; use tower_http::services::ServeDir; @@ -39,11 +40,8 @@ async fn main() { .route("/posts/:post_id", get(handlers::post_handler)) .with_state(posts) .route("/policies", get(handlers::policies_handler)) - .route("/policies/", get(handlers::policies_handler)) .route("/brochure", get(handlers::brochure_handler)) - .route("/brochure/", get(handlers::brochure_handler)) .route("/about", get(handlers::about_handler)) - .route("/about/", get(handlers::about_handler)) .with_state(tutors) .nest_service("/assets", ServeDir::new(assets_dir)) .nest_service("/team", ServeDir::new(tutor_dir)) @@ -55,8 +53,9 @@ async fn main() { .on_response(trace::DefaultOnResponse::new() .level(Level::INFO)) ); + let app = NormalizePathLayer::trim_trailing_slash().layer(app); let addr = env::var("CT_BIND").unwrap_or("0.0.0.0:8000".into()); let listener = tokio::net::TcpListener::bind(addr).await.unwrap(); - axum::serve(listener, app).await.unwrap(); + axum::serve(listener, ServiceExt::<Request>::into_make_service(app)).await.unwrap(); } |