Skip to content
Open
Changes from all 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 packages/fullstack-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ fn serve_dir_cached<S>(mut router: Router<S>, 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));
Expand All @@ -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
Expand Down
Loading