Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions crates/api/src/static_files.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use axum::{
body::Body,
http::{header, Request, StatusCode},
response::{IntoResponse, Response},
response::{IntoResponse, Redirect, Response},
};
use std::{env, path::PathBuf};
use tower::ServiceExt;
Expand All @@ -19,6 +19,18 @@ fn frontend_dir() -> PathBuf {
/// Serve static files with SPA fallback and proper cache headers.
pub async fn static_handler(req: Request<Body>) -> Response {
let frontend_dir = frontend_dir();
let uri = req.uri().clone();

// Redirect root to /?v=1 to workaround the cache issue
let needs_version_redirect = uri.path() == "/"
&& uri
.query()
.map(|q| !q.split('&').any(|pair| pair.starts_with("v=")))
.unwrap_or(true);

if needs_version_redirect {
return Redirect::temporary("/?v=1").into_response();
}

let has_extension = req
.uri()
Expand Down Expand Up @@ -47,7 +59,7 @@ pub async fn static_handler(req: Request<Body>) -> Response {
.unwrap_or(false);
// Don't cache HTML files to allow for SPA updates
let cache_value = if is_html {
"no-cache"
"no-cache, no-store, must-revalidate"
} else {
"public, max-age=31536000, immutable"
};
Expand Down