150 lines
3.1 KiB
Rust
150 lines
3.1 KiB
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 std::path::{Path, PathBuf};
|
|
|
|
use rocket::response::NamedFile;
|
|
use rocket_contrib::templates::Template;
|
|
|
|
#[derive(Debug, Serialize)]
|
|
struct FlashContext {
|
|
flash_name: Option<String>,
|
|
flash_msg: Option<String>,
|
|
}
|
|
|
|
#[get("/<file..>")]
|
|
fn files(file: PathBuf) -> Option<NamedFile> {
|
|
NamedFile::open(Path::new("static/").join(file)).ok()
|
|
}
|
|
|
|
#[get("/art")]
|
|
fn art() -> Template {
|
|
let context = FlashContext {
|
|
flash_name: None,
|
|
flash_msg: None,
|
|
};
|
|
Template::render("art", &context)
|
|
}
|
|
|
|
#[get("/background")]
|
|
fn background() -> Template {
|
|
let context = FlashContext {
|
|
flash_name: None,
|
|
flash_msg: None,
|
|
};
|
|
Template::render("background", &context)
|
|
}
|
|
|
|
#[get("/bacteria")]
|
|
fn bacteria() -> Template {
|
|
let context = FlashContext {
|
|
flash_name: None,
|
|
flash_msg: None,
|
|
};
|
|
Template::render("bacteria", &context)
|
|
}
|
|
|
|
#[get("/computers")]
|
|
fn computers() -> Template {
|
|
let context = FlashContext {
|
|
flash_name: None,
|
|
flash_msg: None,
|
|
};
|
|
Template::render("computers", &context)
|
|
}
|
|
|
|
#[get("/fungi")]
|
|
fn fungi() -> Template {
|
|
let context = FlashContext {
|
|
flash_name: None,
|
|
flash_msg: None,
|
|
};
|
|
Template::render("fungi", &context)
|
|
}
|
|
|
|
#[get("/")]
|
|
fn home() -> Template {
|
|
let context = FlashContext {
|
|
flash_name: None,
|
|
flash_msg: None,
|
|
};
|
|
Template::render("home", &context)
|
|
}
|
|
|
|
#[get("/lists")]
|
|
fn lists() -> Template {
|
|
let context = FlashContext {
|
|
flash_name: None,
|
|
flash_msg: None,
|
|
};
|
|
Template::render("lists", &context)
|
|
}
|
|
|
|
#[get("/plants")]
|
|
fn plants() -> Template {
|
|
let context = FlashContext {
|
|
flash_name: None,
|
|
flash_msg: None,
|
|
};
|
|
Template::render("plants", &context)
|
|
}
|
|
|
|
#[get("/meditation")]
|
|
fn meditation() -> Template {
|
|
let context = FlashContext {
|
|
flash_name: None,
|
|
flash_msg: None,
|
|
};
|
|
Template::render("meditation", &context)
|
|
}
|
|
|
|
#[get("/movement")]
|
|
fn movement() -> Template {
|
|
let context = FlashContext {
|
|
flash_name: None,
|
|
flash_msg: None,
|
|
};
|
|
Template::render("movement", &context)
|
|
}
|
|
|
|
#[get("/travel")]
|
|
fn travel() -> Template {
|
|
let context = FlashContext {
|
|
flash_name: None,
|
|
flash_msg: None,
|
|
};
|
|
Template::render("travel", &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![
|
|
files, art, background, bacteria, computers, fungi, home, lists, plants,
|
|
meditation, movement, travel
|
|
],
|
|
)
|
|
.register(catchers![not_found])
|
|
.attach(Template::fairing())
|
|
.launch();
|
|
}
|