diff --git a/src/rest_api/default.rs b/src/rest_api/default.rs index 6908450..6b3bc52 100644 --- a/src/rest_api/default.rs +++ b/src/rest_api/default.rs @@ -3,6 +3,7 @@ use super::AppState; use actix_web::fs; use actix_web::http::StatusCode; use actix_web::HttpRequest; +use actix_web::Path; use actix_web::Result; pub fn page_400(_req: &HttpRequest) -> Result { @@ -19,6 +20,17 @@ pub fn page_404(_req: &HttpRequest) -> Result { Ok(fs::NamedFile::open("static/404.html")?.set_status_code(StatusCode::NOT_FOUND)) } +pub fn static_file((path, _req): (Path, HttpRequest)) -> Result { + trace!("static/{} Triggered!", path); + + match fs::NamedFile::open(format!("static/{}", path).as_str()) { + Ok(o) => Ok(o), + Err(_) => { + Ok(fs::NamedFile::open("static/404.html")?.set_status_code(StatusCode::NOT_FOUND)) + } + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/rest_api/mod.rs b/src/rest_api/mod.rs index 6f9aebc..2fd4536 100644 --- a/src/rest_api/mod.rs +++ b/src/rest_api/mod.rs @@ -156,6 +156,9 @@ where }) .boxed(), App::new() + .resource("/static/{file}", |r| { + r.method(Method::GET).with(default::static_file) + }) .default_resource(|r| { // 404 for GET request r.method(Method::GET).f(default::page_404);