batflip/src/router.rs

47 lines
1.3 KiB
Rust

use std::fs;
use std::collections::HashMap;
pub fn get_route_data(route: &str) -> String {
// @required - set valid routes here.
let route_map = HashMap::from([
("/", "./public/index.html"),
]);
dbg!(route_map.get(route));
// match route_map.get(route) {
// None => ,
// Some(page) => Some(page),
// };
// Some("test".to_string())
//
//
// High leve list of thigns to do
// 1. get the correct file to retrieve
// 2. parse the file and swap out any dynamic sections
// 3. return the string based response.
let route_file: String = match route {
"/" => {
"
return fs::read_to_string("./public/index.html").unwrap();
},
"/about" => {
return fs::read_to_string("./public/pages/about.html").unwrap();
}
_ if route.contains("assets") => {
let mut public_route: String = "./public".to_string();
public_route.push_str(&route);
return fs::read_to_string(&public_route).unwrap()
},
&_ => {
return fs::read_to_string("./public/404.html").unwrap();
}
}
// fs::read_to_string(route_file).unwrap();
}
// pub fn path_exists(path: &str) -> bool {
// fs::metadata(path).is_ok()
// }