From 73c100ca9621ff9cfa3ca665e14e997524d92160 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 4 Mar 2019 14:08:48 +0100 Subject: Use rocket_contrib StaticFiles module to serve static files. This also changes the structure of the app quite significantly. Instead if generating the html for the index, we simply provide a public/index.html static file instead. For now this seems to make sense, it may not hold in the long run, but that's for another time to worry about. --- src/main.rs | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 1ee6011..5c858aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,31 +17,8 @@ */ #![feature(proc_macro_hygiene, decl_macro)] -use askama::Template; -use rocket::{ - get, - http::RawStr, - routes, - response::NamedFile, -}; -use std::path::PathBuf; - -#[derive(Template)] -#[template(path = "index.html")] -struct IndexTemplate<'a> { - year: &'a str, -} - -#[get("/")] -fn index<'a>() -> IndexTemplate<'static> { - IndexTemplate { year: "2019" } -} - -#[get("/", rank = 99)] -fn public_file(file: &RawStr) -> Option { - NamedFile::open(PathBuf::from("public/").join(file.as_str())).ok() -} - fn main() { - rocket::ignite().mount("/", routes![index, public_file]).launch(); + rocket::ignite() + .mount("/", rocket_contrib::serve::StaticFiles::from("./public")) + .launch(); } -- cgit v1.2.3