rocket-pinboard/src/handlers/static_files.rs

29 lines
656 B
Rust
Raw Normal View History

2020-02-03 21:38:20 +01:00
use rocket::get;
use rocket::response::NamedFile;
use std::path::{Path, PathBuf};
#[get("/<path..>", rank = 5)]
2020-02-03 21:38:20 +01:00
pub(crate) fn all(path: PathBuf) -> Option<NamedFile> {
NamedFile::open(
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("static")
.join(path),
)
.ok()
}
2018-01-01 21:16:55 +01:00
#[cfg(test)]
mod tests {
use rocket::http::Status;
use rocket::local::Client;
#[test]
fn all() {
2020-02-03 21:38:20 +01:00
let client = Client::new(crate::rocket(Some("test"))).unwrap();
2018-01-01 21:16:55 +01:00
// Try to get the main JavaScript file
let res = client.get("/js/pinboard.js").dispatch();
2018-01-01 21:16:55 +01:00
assert_eq!(res.status(), Status::Ok);
}
}