awesome pawsome
This commit is contained in:
33
src/main.rs
33
src/main.rs
@@ -20,7 +20,7 @@ mod loader;
|
||||
use crate::loader::*;
|
||||
|
||||
struct AppState<'a> {
|
||||
pages: Vec<Page>,
|
||||
pub pages: Vec<Page>,
|
||||
env: Environment<'a>,
|
||||
}
|
||||
|
||||
@@ -28,18 +28,29 @@ struct AppState<'a> {
|
||||
async fn serve(req: Request<Incoming>, state: Arc<AppState<'_>>) -> Result<Response<Full<Bytes>>> {
|
||||
println!("Serving {}", req.uri());
|
||||
|
||||
let tmpl = state.env.get_template("hello").unwrap();
|
||||
let guh = tmpl.render(context!(name => "meowmeowmeowmeow!")).unwrap();
|
||||
let guh2 = state.env.get_template("meow").unwrap();
|
||||
let guh3 = guh2.render(context!(meow => "meow")).unwrap();
|
||||
|
||||
let path = req.uri().path();
|
||||
let reply: Bytes = match path {
|
||||
"/" => guh.into(),
|
||||
"/mreow" => guh3.into(),
|
||||
_ => "Invalid path!".into(),
|
||||
let mreow = state.pages.iter().find(|&x| {
|
||||
if let Some(path_x) = &x.header.path {
|
||||
println!("{},{}", path_x, path);
|
||||
if path_x == path {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
});
|
||||
let reply = match mreow {
|
||||
Some(x) => state
|
||||
.env
|
||||
.get_template(&x.header.id)
|
||||
.unwrap()
|
||||
.render(context! {})
|
||||
.unwrap(),
|
||||
None => "?".to_string(),
|
||||
};
|
||||
Ok(Response::new(Full::new(reply)))
|
||||
Ok(Response::new(Full::new(reply.into())))
|
||||
}
|
||||
|
||||
async fn handle_client(client: Async<TcpStream>, state: Arc<AppState<'_>>) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user