aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/controllers/home_controller.rs10
-rw-r--r--src/main.rs3
2 files changed, 12 insertions, 1 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()
+}
diff --git a/src/main.rs b/src/main.rs
index 4e96a65..4876b35 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -26,7 +26,8 @@ fn main() {
.mount("/",
routes![
home_controller::index,
- home_controller::index_json])
+ home_controller::index_json,
+ home_controller::public_file])
.mount("/posts",
routes![
posts_controller::new,