Skip to content

Commit 7c53882

Browse files
committed
fix: fix file server when file does not exist
1 parent 8956307 commit 7c53882

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/router.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ impl Router {
5757

5858
let safe_filename = safe_filename.unwrap();
5959
let filepath = PathBuf::from(dir_path).join(safe_filename);
60+
if !filepath.exists() {
61+
let catch_all_route = Route::from_str("GET /*")?;
62+
if let Some(catch_all_callback) = self.routes.get(&catch_all_route) {
63+
return catch_all_callback(request);
64+
} else {
65+
return HttpResponseBuilder::new()
66+
.set_status(HttpStatusCode::NotFound)
67+
.build();
68+
}
69+
}
70+
6071
let mime_type = mime_guess::from_path(&filepath).first_or_octet_stream();
6172
let content = fs::read(filepath)?;
6273

0 commit comments

Comments
 (0)