Add support for serving static files from static/
This commit is contained in:
parent
3a66d85dcd
commit
e742a997dc
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
Loading…
Reference in New Issue