Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explorer public folder being relative to the binary #447

Merged
merged 2 commits into from
Nov 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion explorer/src/jobs/mixmining.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
11 changes: 10 additions & 1 deletion explorer/src/jobs/topology.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
8 changes: 7 additions & 1 deletion explorer/src/main.rs
Original file line number Diff line number Diff line change
@@ -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()
});

6 changes: 3 additions & 3 deletions explorer/src/utils/file.rs
Original file line number Diff line number Diff line change
@@ -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,
};