summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2024-09-28 09:55:53 -0400
committerAdam T. Carpenter <atc@53hor.net>2024-09-28 09:55:53 -0400
commitd1c9f549d3a45118f0a563ddbe07c18fbc8ab660 (patch)
tree05c27b0976bc359bf512d798376b59269fd64fa3 /src
parent45a658e693ab9779ddd364d2acb651178db2dc99 (diff)
downloadcarpentertutoring-blog.tar.xz
carpentertutoring-blog.zip
fix: real fix for trailing backslash handlingblog
Diffstat (limited to 'src')
-rw-r--r--src/main.rs11
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();
}