diff --git a/src/main.rs b/src/main.rs index 5ebe7e0..d524d0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,18 +5,15 @@ extern crate rocket; use colored::*; use rocket::fairing::{Fairing, Info, Kind}; -use rocket::http::Status; -use rocket::response::status; use rocket::{config::TlsConfig, fs::NamedFile}; use rocket_dyn_templates::Template; -use std::collections::HashMap; use std::net::IpAddr; use std::path::Path; use std::str::FromStr; #[get("/")] async fn file_server(path: std::path::PathBuf) -> Option { - let mut path = Path::new(&std::env::var("ROOT").unwrap()).join(path); + let mut path = Path::new(&std::env::var("ROOT").unwrap_or(".".to_string())).join(path); if path.is_dir() { path.push("index.html") } @@ -29,21 +26,43 @@ struct IndexContext<'r> { title: &'r String, } +#[derive(Responder)] +enum Resp { + #[response(status = 200)] + Index(Template), + #[response(status = 404)] + NotFound(String), + #[response(status = 200)] + File(NamedFile), +} + #[catch(404)] -fn not_found(request: &rocket::Request) -> status::Custom