46 lines
977 B
Rust
46 lines
977 B
Rust
#![feature(proc_macro_hygiene, decl_macro)]
|
|
|
|
#[macro_use]
|
|
extern crate log;
|
|
#[macro_use]
|
|
extern crate rocket;
|
|
extern crate rocket_contrib;
|
|
#[macro_use]
|
|
extern crate serde_derive;
|
|
extern crate tera;
|
|
|
|
use rocket_contrib::templates::Template;
|
|
|
|
#[derive(Debug, Serialize)]
|
|
struct FlashContext {
|
|
flash_name: Option<String>,
|
|
flash_msg: Option<String>,
|
|
}
|
|
|
|
#[get("/")]
|
|
fn index() -> Template {
|
|
let context = FlashContext {
|
|
flash_name: None,
|
|
flash_msg: None,
|
|
};
|
|
Template::render("index", &context)
|
|
}
|
|
|
|
#[catch(404)]
|
|
fn not_found() -> Template {
|
|
debug!("404 Page Not Found");
|
|
let context = FlashContext {
|
|
flash_name: Some("error".to_string()),
|
|
flash_msg: Some("No resource found for given URL".to_string()),
|
|
};
|
|
Template::render("not_found", context)
|
|
}
|
|
|
|
fn main() {
|
|
rocket::ignite()
|
|
.mount("/", routes![index])
|
|
.register(catchers![not_found])
|
|
.attach(Template::fairing())
|
|
.launch();
|
|
}
|