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 /src | |
parent | 45a658e693ab9779ddd364d2acb651178db2dc99 (diff) | |
download | carpentertutoring-d1c9f549d3a45118f0a563ddbe07c18fbc8ab660.tar.xz carpentertutoring-d1c9f549d3a45118f0a563ddbe07c18fbc8ab660.zip |
fix: real fix for trailing backslash handlingblog
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 11 |
1 files changed, 5 insertions, 6 deletions
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(); } |