diff --git a/backend/src/main.rs b/backend/src/main.rs index e427d51..f1cd21c 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -1,10 +1,4 @@ -use rocket::{ - Request, - fs::{ - FileServer, - rewrite::{File, Rewrite}, - }, -}; +use rocket::fs::FileServer; #[macro_use] extern crate rocket; @@ -33,8 +27,16 @@ fn get_users(user_list: &rocket::State>) -> items::PersonList } } -fn redir_missing<'r>(p: Option>, _req: &Request<'_>) -> Option> { - Some(p.unwrap_or_else(|| Rewrite::File(File::checked("../frontend/dist/index.html")))) +#[get("/<_..>", rank = 20)] +async fn index_fallback() -> Option { + // Try multiple paths for robustness + let paths = ["../frontend/dist/index.html", "frontend/dist/index.html"]; + for path in paths { + if let Ok(file) = rocket::fs::NamedFile::open(path).await { + return Some(file); + } + } + None } #[launch] @@ -59,8 +61,6 @@ fn rocket() -> _ { rocket::build() .manage(user_list) .mount("/api", routes![get_users, get_user]) - .mount( - "/", - FileServer::new("../frontend/dist").rewrite(redir_missing), - ) + .mount("/", routes![index_fallback]) + .mount("/", FileServer::new("../frontend/dist")) }