Skip to content

Commit

Permalink
send caching headers for static content
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Kruse committed Aug 13, 2023
1 parent 4c0731d commit 0c4622a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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))]
Expand Down Expand Up @@ -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")))
Expand All @@ -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)
Expand Down

0 comments on commit 0c4622a

Please sign in to comment.