diff --git a/packages/fullstack-server/src/server.rs b/packages/fullstack-server/src/server.rs index a8a1678ef8..925f61ca2e 100644 --- a/packages/fullstack-server/src/server.rs +++ b/packages/fullstack-server/src/server.rs @@ -407,7 +407,7 @@ fn serve_dir_cached(mut router: Router, public_path: &Path, directory: &Pa where S: Send + Sync + Clone + 'static, { - use tower_http::services::ServeFile; + use tower_http::services::{ServeDir, ServeFile}; let dir = std::fs::read_dir(directory) .unwrap_or_else(|e| panic!("Couldn't read public directory at {:?}: {}", &directory, e)); @@ -430,7 +430,19 @@ where ); if path.is_dir() { - router = serve_dir_cached(router, public_path, &path); + // In debug builds, serve directories dynamically so new files (like + // wasm patch modules) are immediately visible without rebuilding + // the router. In release, keep the previous cached traversal + // behaviour. + #[cfg(debug_assertions)] + { + router = router.nest_service(&route, ServeDir::new(&path)); + } + + #[cfg(not(debug_assertions))] + { + router = serve_dir_cached(router, public_path, &path); + } } else { let serve_file = ServeFile::new(&path).precompressed_br(); // All cached assets are served at the root of the asset directory. If we know an asset