@@ -19,17 +19,21 @@ fn frontend_dir() -> PathBuf {
1919/// Serve static files with SPA fallback and proper cache headers.
2020pub async fn static_handler ( req : Request < Body > ) -> Response {
2121 let frontend_dir = frontend_dir ( ) ;
22+ let path = req. uri ( ) . path ( ) . to_owned ( ) ;
23+ let is_root = path == "/" ;
2224
23- let has_extension = req
24- . uri ( )
25- . path ( )
25+ let has_extension = path
2626 . rsplit ( '/' )
2727 . next ( )
2828 . map ( |segment| segment. contains ( '.' ) )
2929 . unwrap_or ( false ) ;
3030
3131 // Serve static files if they have an extension, otherwise fallback to the index.html file
32- let result = if has_extension {
32+ let result = if is_root {
33+ ServeFile :: new ( frontend_dir. join ( "index.html" ) )
34+ . oneshot ( req)
35+ . await
36+ } else if has_extension {
3337 ServeDir :: new ( frontend_dir. clone ( ) ) . oneshot ( req) . await
3438 } else {
3539 ServeDir :: new ( frontend_dir. clone ( ) )
@@ -46,7 +50,7 @@ pub async fn static_handler(req: Request<Body>) -> Response {
4650 . map ( |ct| ct. contains ( "text/html" ) )
4751 . unwrap_or ( false ) ;
4852 // Don't cache HTML files to allow for SPA updates
49- let cache_value = if is_html {
53+ let cache_value = if is_html || is_root {
5054 "no-cache, no-store, must-revalidate"
5155 } else {
5256 "public, max-age=31536000, immutable"
0 commit comments