use std::fs; pub fn get_route_data(route: &str) -> String { let route_data: String; match route { "/" => { route_data = fs::read_to_string("./public/index.html").unwrap(); }, "/about" => { route_data = fs::read_to_string("./public/pages/about.html").unwrap(); } &_ => { let mut public_path: String = "./public".to_string(); if path_exists(&public_path) { if public_path.contains("images") { route_data = fs::read(public_path).unwrap(); } else { route_data = fs::read_to_string(public_path).unwrap(); } } else { route_data = fs::read_to_string("./public/404.html").unwrap(); } } } route_data } pub fn path_exists(path: &str) -> bool { fs::metadata(path).is_ok() }