fix react paths
This commit is contained in:
parent
5d3f64f558
commit
77ec776377
@ -1,10 +1,4 @@
|
|||||||
use rocket::{
|
use rocket::fs::FileServer;
|
||||||
Request,
|
|
||||||
fs::{
|
|
||||||
FileServer,
|
|
||||||
rewrite::{File, Rewrite},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
@ -33,8 +27,16 @@ fn get_users(user_list: &rocket::State<Vec<items::Person>>) -> items::PersonList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn redir_missing<'r>(p: Option<Rewrite<'r>>, _req: &Request<'_>) -> Option<Rewrite<'r>> {
|
#[get("/<_..>", rank = 20)]
|
||||||
Some(p.unwrap_or_else(|| Rewrite::File(File::checked("../frontend/dist/index.html"))))
|
async fn index_fallback() -> Option<rocket::fs::NamedFile> {
|
||||||
|
// 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]
|
#[launch]
|
||||||
@ -59,8 +61,6 @@ fn rocket() -> _ {
|
|||||||
rocket::build()
|
rocket::build()
|
||||||
.manage(user_list)
|
.manage(user_list)
|
||||||
.mount("/api", routes![get_users, get_user])
|
.mount("/api", routes![get_users, get_user])
|
||||||
.mount(
|
.mount("/", routes![index_fallback])
|
||||||
"/",
|
.mount("/", FileServer::new("../frontend/dist"))
|
||||||
FileServer::new("../frontend/dist").rewrite(redir_missing),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user