diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-01-14 20:01:33 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-01-14 20:01:33 +0100 |
commit | 099624218ca84503d31c0f4c21139138d55d0630 (patch) | |
tree | 421a4c1ac81fca011ae4752c50246a86f520a277 /src/controllers | |
parent | 47e46a6e00c47622e99cfd65083887b3dce02716 (diff) | |
download | rocket-blog-099624218ca84503d31c0f4c21139138d55d0630.tar.gz rocket-blog-099624218ca84503d31c0f4c21139138d55d0630.tar.bz2 rocket-blog-099624218ca84503d31c0f4c21139138d55d0630.zip |
Serve static files from public directory if no other route match.
Diffstat (limited to 'src/controllers')
-rw-r--r-- | src/controllers/home_controller.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/controllers/home_controller.rs b/src/controllers/home_controller.rs index 563be40..6423a30 100644 --- a/src/controllers/home_controller.rs +++ b/src/controllers/home_controller.rs @@ -1,5 +1,7 @@ use ::{models, utils}; +use rocket; use rocket_contrib::Json; +use std::path::PathBuf; #[derive(BartDisplay, Serialize)] #[template = "templates/index.html"] @@ -23,3 +25,11 @@ fn index(conn: utils::DbConn) -> utils::Page<IndexTemplate> { fn index_json(conn: utils::DbConn) -> Json<Vec<models::Post>> { Json(models::Post::get_all(conn)) } + +// +// Serve files from the public directory if no routes matches. +// +#[get("/<file..>", rank = 99)] +fn public_file(file: PathBuf) -> Option<rocket::response::NamedFile> { + rocket::response::NamedFile::open(PathBuf::from("public/").join(file)).ok() +} |