Skip to content

Commit

Permalink
add cache control to leptos pkg dir
Browse files Browse the repository at this point in the history
  • Loading branch information
akarras committed Jan 21, 2024
1 parent c357eaa commit 8b2154b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 10 additions & 2 deletions ultros/src/leptos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions ultros/src/web.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down

0 comments on commit 8b2154b

Please sign in to comment.