diff options
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(); } |