From 8b2154b05478e162cf0cfa814ae7f461def2e294 Mon Sep 17 00:00:00 2001 From: akarras Date: Sun, 21 Jan 2024 16:25:39 -0700 Subject: [PATCH] add cache control to leptos pkg dir --- ultros/src/leptos.rs | 12 ++++++++++-- ultros/src/web.rs | 12 ++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ultros/src/leptos.rs b/ultros/src/leptos.rs index b59a60c2..49abd4a5 100644 --- a/ultros/src/leptos.rs +++ b/ultros/src/leptos.rs @@ -6,17 +6,19 @@ use std::{error::Error, sync::Arc}; /// you should be able to build and serve leptos with one install step. /// use axum::{ - body::{Body, HttpBody}, + body::Body, extract::State, - http::Request, + http::{HeaderValue, Request}, response::{IntoResponse, Response}, routing::get, Extension, Router, }; use git_const::git_short_hash; +use hyper::{body::HttpBody, header}; use leptos::*; use leptos_axum::generate_route_list; use leptos_router::RouteListing; +use tower_http::set_header::SetResponseHeader; use tracing::instrument; use ultros_api_types::world_helper::WorldHelper; use ultros_app::*; @@ -66,6 +68,12 @@ pub(crate) async fn create_leptos_app( let git_hash = git_short_hash!(); leptos_options.site_pkg_dir = ["pkg/", git_hash].concat(); let cargo_leptos_service = HandleError::new(ServeDir::new(&bundle_filepath), handle_file_error); + // #[cfg(not(debug_assertions))] + let cargo_leptos_service = SetResponseHeader::appending( + cargo_leptos_service, + header::CACHE_CONTROL, + HeaderValue::from_static("max-age=86400"), + ); tracing::info!("Serving pkg dir: {bundle_filepath}"); /// Convert the Errors from ServeDir to a type that implements IntoResponse async fn handle_file_error(err: std::io::Error) -> (StatusCode, String) { diff --git a/ultros/src/web.rs b/ultros/src/web.rs index bd047fc5..269f6e15 100644 --- a/ultros/src/web.rs +++ b/ultros/src/web.rs @@ -1,11 +1,11 @@ mod alerts_websocket; -pub mod api; +pub(crate) mod api; pub(crate) mod character_verifier_service; -pub mod country_code_decoder; -pub mod error; -pub mod item_card; -pub mod oauth; -pub mod sitemap; +pub(crate) mod country_code_decoder; +pub(crate) mod error; +pub(crate) mod item_card; +pub(crate) mod oauth; +pub(crate) mod sitemap; use anyhow::Error; use axum::body::{Empty, Full};