Add support for serving static files from static/

This commit is contained in:
Paul van Tilburg 2017-12-06 15:34:56 +01:00
parent 3a66d85dcd
commit e742a997dc
2 changed files with 10 additions and 1 deletions

View File

@ -3,6 +3,8 @@
extern crate rocket;
mod static_files;
#[get("/")]
fn index() -> &'static str {
"Hello, world!"
@ -10,6 +12,6 @@ fn index() -> &'static str {
fn main() {
rocket::ignite()
.mount("/", routes![index])
.mount("/", routes![index, static_files::all])
.launch();
}

7
src/static_files.rs Normal file
View File

@ -0,0 +1,7 @@
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()
}