From cb18954ef2dde477dcf8719ce95dbc27ceb7b061 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Fri, 24 Aug 2018 14:00:36 -0700 Subject: [PATCH] Use 'StaticFiles' in todo example. --- examples/todo/Cargo.toml | 2 +- examples/todo/src/main.rs | 7 +++---- examples/todo/src/static_files.rs | 7 ------- 3 files changed, 4 insertions(+), 12 deletions(-) delete mode 100644 examples/todo/src/static_files.rs diff --git a/examples/todo/Cargo.toml b/examples/todo/Cargo.toml index 01c9bb48..4281c31a 100644 --- a/examples/todo/Cargo.toml +++ b/examples/todo/Cargo.toml @@ -19,4 +19,4 @@ rand = "0.5" [dependencies.rocket_contrib] path = "../../contrib/lib" default_features = false -features = ["tera_templates", "diesel_sqlite_pool"] +features = ["tera_templates", "diesel_sqlite_pool", "static_files"] diff --git a/examples/todo/src/main.rs b/examples/todo/src/main.rs index 51536365..5d622e3c 100644 --- a/examples/todo/src/main.rs +++ b/examples/todo/src/main.rs @@ -6,15 +6,13 @@ #[macro_use] extern crate serde_derive; extern crate rocket_contrib; -mod static_files; mod task; #[cfg(test)] mod tests; use rocket::Rocket; use rocket::request::{Form, FlashMessage}; use rocket::response::{Flash, Redirect}; -use rocket_contrib::Template; -use rocket_contrib::databases::database; +use rocket_contrib::{Template, databases::database, static_files::StaticFiles}; use diesel::SqliteConnection; use task::{Task, Todo}; @@ -76,7 +74,8 @@ fn index(msg: Option, conn: DbConn) -> Template { fn rocket() -> (Rocket, Option) { let rocket = rocket::ignite() .attach(DbConn::fairing()) - .mount("/", routes![index, static_files::all]) + .mount("/", StaticFiles::from("static/")) + .mount("/", routes![index]) .mount("/todo", routes![new, toggle, delete]) .attach(Template::fairing()); diff --git a/examples/todo/src/static_files.rs b/examples/todo/src/static_files.rs deleted file mode 100644 index 0336de7a..00000000 --- a/examples/todo/src/static_files.rs +++ /dev/null @@ -1,7 +0,0 @@ -use std::path::{Path, PathBuf}; -use rocket::response::NamedFile; - -#[get("/", rank = 5)] -fn all(path: PathBuf) -> Option { - NamedFile::open(Path::new("static/").join(path)).ok() -}