From 0c4622ae787b344c60a89d5f04a7b11b60673844 Mon Sep 17 00:00:00 2001 From: Christian Kruse Date: Sun, 13 Aug 2023 13:19:02 +0200 Subject: [PATCH] send caching headers for static content --- src/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index ce2eea0f..f521ca16 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use std::{net::SocketAddr, time::Duration}; -use axum::Router; +use axum::{middleware::map_response_with_state, Router}; #[cfg(debug_assertions)] use axum_login::axum_sessions::async_session::CookieStore as SessionStore; #[cfg(not(debug_assertions))] @@ -98,7 +98,7 @@ async fn main() { tracing::debug!("listening on {}", addr); - let app = app + let static_router: AppRouter = Router::new() .nest_service("/static", serve_dir) .route_service("/favicon.ico", ServeFile::new(utils::static_file_path("favicon.ico"))) .route_service("/robots.txt", ServeFile::new(utils::static_file_path("robots.txt"))) @@ -112,6 +112,13 @@ async fn main() { "/.well-known/security.txt", ServeFile::new(utils::static_file_path("security.txt")), ) + .layer(map_response_with_state( + chrono::Duration::days(365), + middleware::caching_middleware, + )); + + let app = app + .merge(static_router) .with_state(state) .layer(auth_layer) .layer(session_layer)