summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs11
2 files changed, 6 insertions, 7 deletions
diff --git a/Cargo.toml b/Cargo.toml
index e8104bd..30fd4f8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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();
}