diff --git a/explorer/src/jobs/mixmining.rs b/explorer/src/jobs/mixmining.rs index efc43ffa33f..e55917c2c37 100644 --- a/explorer/src/jobs/mixmining.rs +++ b/explorer/src/jobs/mixmining.rs @@ -7,6 +7,15 @@ pub async fn renew_periodically(validator_base_url: &str) -> Result<(), Error> { let url = format!("{}/{}", validator_base_url, RELATIVE_PATH); let topology_json = reqwest::get(&url).await?.text().await?; - file::save(topology_json, "public/downloads/mixmining.json"); + + let save_path = std::env::current_exe() + .expect("Failed to evaluate current exe path") + .parent() + .expect("the binary itself has no parent path?!") + .join("public") + .join("downloads") + .join("mixmining.json"); + + file::save(topology_json, save_path); Ok(()) } diff --git a/explorer/src/jobs/topology.rs b/explorer/src/jobs/topology.rs index 680b8acafb8..5d1f175a4e5 100644 --- a/explorer/src/jobs/topology.rs +++ b/explorer/src/jobs/topology.rs @@ -7,6 +7,15 @@ pub async fn renew_periodically(validator_base_url: &str) -> Result<(), Error> { let url = format!("{}/{}", validator_base_url, RELATIVE_PATH); let topology_json = reqwest::get(&url).await?.text().await?; - file::save(topology_json, "public/downloads/topology.json"); + + let save_path = std::env::current_exe() + .expect("Failed to evaluate current exe path") + .parent() + .expect("the binary itself has no parent path?!") + .join("public") + .join("downloads") + .join("topology.json"); + + file::save(topology_json, save_path); Ok(()) } diff --git a/explorer/src/main.rs b/explorer/src/main.rs index 24df8945e0d..475e84587b7 100644 --- a/explorer/src/main.rs +++ b/explorer/src/main.rs @@ -37,9 +37,15 @@ async fn main() { let matches = parse_args(); let validator_base_url = matches.value_of(VALIDATOR_ARG).unwrap(); + let public_path = std::env::current_exe() + .expect("Failed to evaluate current exe path") + .parent() + .expect("the binary itself has no parent path?!") + .join("public"); + tokio::task::spawn_blocking(|| { rocket::ignite() - .mount("/", StaticFiles::from("public")) + .mount("/", StaticFiles::from(public_path)) .launch() }); diff --git a/explorer/src/utils/file.rs b/explorer/src/utils/file.rs index 33ac0dd7f08..929880b2932 100644 --- a/explorer/src/utils/file.rs +++ b/explorer/src/utils/file.rs @@ -1,10 +1,10 @@ use std::{fs::File, io::Write, path::Path}; -pub fn save(text: String, path_str: &str) { - let path = Path::new(path_str); +pub fn save<P: AsRef<Path>>(text: String, path: P) { + let path = path.as_ref(); let display = path.display(); - let mut file = match File::create(&path) { + let mut file = match File::create(path) { Err(why) => panic!("couldn't open {}: {}", display, why), Ok(file) => file, };