From 50adf72a2391bbd840eb139a5f82e503530c65fb Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 2 Mar 2019 22:39:53 +0100 Subject: Add favicon and route to get public files. --- src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index e283b21..f97f600 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,18 @@ #![feature(proc_macro_hygiene, decl_macro)] -use rocket::{get, routes}; +use rocket::{get, http::RawStr, routes, response::NamedFile}; +use std::path::PathBuf; #[get("/")] fn index() -> &'static str { "Holahey, Jävlar!" } +#[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]).launch(); + rocket::ignite().mount("/", routes![index, public_file]).launch(); } -- cgit v1.2.3