Skip to content

Commit 830a89c

Browse files
Explorer public folder being relative to the binary (#447)
* Explorer public folder being relative to the binary * Qualifying the public mounting path Co-authored-by: Dave <futurechimp@users.noreply.github.com>
1 parent c18766a commit 830a89c

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

explorer/src/jobs/mixmining.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ pub async fn renew_periodically(validator_base_url: &str) -> Result<(), Error> {
77
let url = format!("{}/{}", validator_base_url, RELATIVE_PATH);
88

99
let topology_json = reqwest::get(&url).await?.text().await?;
10-
file::save(topology_json, "public/downloads/mixmining.json");
10+
11+
let save_path = std::env::current_exe()
12+
.expect("Failed to evaluate current exe path")
13+
.parent()
14+
.expect("the binary itself has no parent path?!")
15+
.join("public")
16+
.join("downloads")
17+
.join("mixmining.json");
18+
19+
file::save(topology_json, save_path);
1120
Ok(())
1221
}

explorer/src/jobs/topology.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ pub async fn renew_periodically(validator_base_url: &str) -> Result<(), Error> {
77
let url = format!("{}/{}", validator_base_url, RELATIVE_PATH);
88

99
let topology_json = reqwest::get(&url).await?.text().await?;
10-
file::save(topology_json, "public/downloads/topology.json");
10+
11+
let save_path = std::env::current_exe()
12+
.expect("Failed to evaluate current exe path")
13+
.parent()
14+
.expect("the binary itself has no parent path?!")
15+
.join("public")
16+
.join("downloads")
17+
.join("topology.json");
18+
19+
file::save(topology_json, save_path);
1120
Ok(())
1221
}

explorer/src/main.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ async fn main() {
3737
let matches = parse_args();
3838
let validator_base_url = matches.value_of(VALIDATOR_ARG).unwrap();
3939

40+
let public_path = std::env::current_exe()
41+
.expect("Failed to evaluate current exe path")
42+
.parent()
43+
.expect("the binary itself has no parent path?!")
44+
.join("public");
45+
4046
tokio::task::spawn_blocking(|| {
4147
rocket::ignite()
42-
.mount("/", StaticFiles::from("public"))
48+
.mount("/", StaticFiles::from(public_path))
4349
.launch()
4450
});
4551

explorer/src/utils/file.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::{fs::File, io::Write, path::Path};
22

3-
pub fn save(text: String, path_str: &str) {
4-
let path = Path::new(path_str);
3+
pub fn save<P: AsRef<Path>>(text: String, path: P) {
4+
let path = path.as_ref();
55
let display = path.display();
66

7-
let mut file = match File::create(&path) {
7+
let mut file = match File::create(path) {
88
Err(why) => panic!("couldn't open {}: {}", display, why),
99
Ok(file) => file,
1010
};

0 commit comments

Comments
 (0)