Take path relative to the Cargo manifest dir
This commit is contained in:
parent
bc18307da9
commit
3017d53256
|
@ -1,9 +1,14 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
use rocket::response::NamedFile;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[get("/<path..>", rank = 5)]
|
||||
fn all(path: PathBuf) -> Option<NamedFile> {
|
||||
NamedFile::open(Path::new("static/").join(path)).ok()
|
||||
pub fn all(path: PathBuf) -> Option<NamedFile> {
|
||||
NamedFile::open(
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("static")
|
||||
.join(path),
|
||||
)
|
||||
.ok()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
10
src/main.rs
10
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<Vec<models::note::Note>>;
|
||||
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue