a8bfc771ff9a575ccea360f4d8e3ba389be9e848 — Thomas Letan 1 year, 1 month ago a9dfab5 master
refactor: Rely on the newly introduced StaticFiles

This is one of the very interested features introduces by
rocket-0.4.0-rc.1.
1 files changed, 3 insertions(+), 9 deletions(-)

M src/main.rs
M src/main.rs => src/main.rs +3 -9
@@ 22,14 22,13 @@ extern crate pretty_env_logger;
 extern crate ogmarkup;
 extern crate base64;
 
-use std::path::{PathBuf, Path};
-
 use diesel::prelude::*;
 
 use rocket::request::FlashMessage;
-use rocket::response::{NamedFile, Content};
+use rocket::response::Content;
 use rocket::http::{ContentType, MediaType};
 use rocket_contrib::templates::Template;
+use rocket_contrib::serve::StaticFiles;
 
 pub mod errors;
 pub mod db;


@@ 98,11 97,6 @@ fn images(
     Ok(Content(ContentType(<MediaType>::PNG), img.content))
 }
 
-#[get("/static/<file..>", rank = 2)]
-fn static_files(file: PathBuf) -> Option<NamedFile> {
-    NamedFile::open(Path::new("static/").join(file)).ok()
-}
-
 fn run() -> Result <(), Error> {
     rocket::ignite()
         .mount("/", routes![


@@ 121,8 115,8 @@ fn run() -> Result <(), Error> {
             routes::characters::new_future_sheet,
             routes::characters::edit_future_sheet,
             routes::characters::edit_future_sheet_post,
-            static_files,
         ])
+        .mount("/static", StaticFiles::from("static"))
         .attach(PgConn::fairing())
         .attach(Template::fairing())
         .launch();