diff --git a/src/handlers/static_files.rs b/src/handlers/static_files.rs index 7186ff3..65e840d 100644 --- a/src/handlers/static_files.rs +++ b/src/handlers/static_files.rs @@ -1,9 +1,14 @@ -use std::path::{Path, PathBuf}; use rocket::response::NamedFile; +use std::path::{Path, PathBuf}; #[get("/", rank = 5)] -fn all(path: PathBuf) -> Option { - NamedFile::open(Path::new("static/").join(path)).ok() +pub fn all(path: PathBuf) -> Option { + NamedFile::open( + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("static") + .join(path), + ) + .ok() } #[cfg(test)] diff --git a/src/main.rs b/src/main.rs index e53533c..d1442e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,8 +16,6 @@ mod handlers; mod models; use rocket::Rocket; -use std::fs::File; -use std::io::prelude::*; use std::sync::RwLock; type NoteStore = RwLock>; @@ -28,8 +26,14 @@ pub struct Config { } fn rocket(notes_path: Option<&str>) -> Rocket { + use std::fs::File; + use std::io::prelude::*; + use std::path::Path; + let mut config_data = String::new(); - let mut config_file = File::open("config.toml").expect("Cannot find config file: config.toml"); + let config_file_name = Path::new(env!("CARGO_MANIFEST_DIR")).join("config.toml"); + let mut config_file = + File::open(config_file_name).expect("Cannot find config file: config.toml"); config_file .read_to_string(&mut config_data) .expect("Cannot read config file: config.toml");