mirror of https://github.com/rwf2/Rocket.git
Use 'StaticFiles' in todo example.
This commit is contained in:
parent
2821711ed3
commit
cb18954ef2
|
@ -19,4 +19,4 @@ rand = "0.5"
|
||||||
[dependencies.rocket_contrib]
|
[dependencies.rocket_contrib]
|
||||||
path = "../../contrib/lib"
|
path = "../../contrib/lib"
|
||||||
default_features = false
|
default_features = false
|
||||||
features = ["tera_templates", "diesel_sqlite_pool"]
|
features = ["tera_templates", "diesel_sqlite_pool", "static_files"]
|
||||||
|
|
|
@ -6,15 +6,13 @@
|
||||||
#[macro_use] extern crate serde_derive;
|
#[macro_use] extern crate serde_derive;
|
||||||
extern crate rocket_contrib;
|
extern crate rocket_contrib;
|
||||||
|
|
||||||
mod static_files;
|
|
||||||
mod task;
|
mod task;
|
||||||
#[cfg(test)] mod tests;
|
#[cfg(test)] mod tests;
|
||||||
|
|
||||||
use rocket::Rocket;
|
use rocket::Rocket;
|
||||||
use rocket::request::{Form, FlashMessage};
|
use rocket::request::{Form, FlashMessage};
|
||||||
use rocket::response::{Flash, Redirect};
|
use rocket::response::{Flash, Redirect};
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::{Template, databases::database, static_files::StaticFiles};
|
||||||
use rocket_contrib::databases::database;
|
|
||||||
use diesel::SqliteConnection;
|
use diesel::SqliteConnection;
|
||||||
|
|
||||||
use task::{Task, Todo};
|
use task::{Task, Todo};
|
||||||
|
@ -76,7 +74,8 @@ fn index(msg: Option<FlashMessage>, conn: DbConn) -> Template {
|
||||||
fn rocket() -> (Rocket, Option<DbConn>) {
|
fn rocket() -> (Rocket, Option<DbConn>) {
|
||||||
let rocket = rocket::ignite()
|
let rocket = rocket::ignite()
|
||||||
.attach(DbConn::fairing())
|
.attach(DbConn::fairing())
|
||||||
.mount("/", routes![index, static_files::all])
|
.mount("/", StaticFiles::from("static/"))
|
||||||
|
.mount("/", routes![index])
|
||||||
.mount("/todo", routes![new, toggle, delete])
|
.mount("/todo", routes![new, toggle, delete])
|
||||||
.attach(Template::fairing());
|
.attach(Template::fairing());
|
||||||
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
use rocket::response::NamedFile;
|
|
||||||
|
|
||||||
#[get("/<path..>", rank = 5)]
|
|
||||||
fn all(path: PathBuf) -> Option<NamedFile> {
|
|
||||||
NamedFile::open(Path::new("static/").join(path)).ok()
|
|
||||||
}
|
|
Loading…
Reference in New Issue