|
|
|
@ -2,26 +2,37 @@
|
|
|
|
|
|
|
|
|
|
#[macro_use] extern crate rocket;
|
|
|
|
|
|
|
|
|
|
use rocket::Request;
|
|
|
|
|
use rocket_contrib::templates::Template;
|
|
|
|
|
|
|
|
|
|
#[derive(serde::Serialize)]
|
|
|
|
|
struct Context {
|
|
|
|
|
name: String,
|
|
|
|
|
struct IndexContext {
|
|
|
|
|
name: &'static str,
|
|
|
|
|
items: Vec<&'static str>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[catch(404)]
|
|
|
|
|
fn not_found(req: &Request<'_>) -> Template {
|
|
|
|
|
println!("{:#?}", req);
|
|
|
|
|
let dbg = format!("{:?}", req);
|
|
|
|
|
let mut map = std::collections::HashMap::new();
|
|
|
|
|
map.insert("title", "Page not found");
|
|
|
|
|
map.insert("path", req.uri().path());
|
|
|
|
|
map.insert("req", &dbg);
|
|
|
|
|
Template::render("error/404", &map)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[get("/")]
|
|
|
|
|
fn index() -> Template {
|
|
|
|
|
let c = String::from("home");
|
|
|
|
|
let context = Context { name: c, items: vec!["One", "Two", "Three"] };
|
|
|
|
|
let context = IndexContext { name: "home", items: vec!["One", "Two", "Three"] };
|
|
|
|
|
Template::render("index", &context)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
rocket::ignite()
|
|
|
|
|
.attach(Template::fairing())
|
|
|
|
|
.mount("/", routes![index]).launch();
|
|
|
|
|
.mount("/", routes![index])
|
|
|
|
|
.register(catchers![not_found])
|
|
|
|
|
.launch();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|