|
@ -4,21 +4,27 @@ use rocket::fs::NamedFile; |
|
|
// Error type 404
|
|
|
// Error type 404
|
|
|
use rocket::response::status::NotFound;
|
|
|
use rocket::response::status::NotFound;
|
|
|
|
|
|
|
|
|
|
|
|
// Responder type Template
|
|
|
|
|
|
use rocket_dyn_templates::{ Template };
|
|
|
|
|
|
|
|
|
|
|
|
use crate::build_rocket::{ templates, config };
|
|
|
|
|
|
|
|
|
// Configure requests
|
|
|
// Configure requests
|
|
|
// generate routes, set attributes
|
|
|
// generate routes, set attributes
|
|
|
// set http method
|
|
|
// set http method
|
|
|
// set uri
|
|
|
// set uri
|
|
|
#[route(GET, uri = "/")]
|
|
|
|
|
|
|
|
|
#[get("/")]
|
|
|
// if success call handler
|
|
|
// if success call handler
|
|
|
pub async fn index() -> Result<NamedFile, NotFound<String>> {
|
|
|
pub async fn index() -> Result<NamedFile, NotFound<String>> {
|
|
|
|
|
|
|
|
|
NamedFile::open("templates/index.html").await.map_err(|e|NotFound(e.to_string()))
|
|
|
NamedFile::open("templates/index.html").await.map_err(|e|NotFound(e.to_string()))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// serve other pages (html GET)
|
|
|
// serve other pages (html GET)
|
|
|
// create routes for pages
|
|
|
// create routes for pages
|
|
|
#[get("/experiments")]
|
|
|
#[get("/experiments")]
|
|
|
pub async fn experiments() -> Option<NamedFile> {
|
|
|
|
|
|
NamedFile::open("templates/experiments.html").await.ok()
|
|
|
|
|
|
|
|
|
pub async fn experiments() -> Result<NamedFile, NotFound<String>> {
|
|
|
|
|
|
NamedFile::open("templates/experiments.html").await.map_err(|e|NotFound(e.to_string()))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#[get("/permaculture")]
|
|
|
#[get("/permaculture")]
|
|
@ -127,8 +133,17 @@ use rocket::response::status::NotFound; |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#[get("/privacy")]
|
|
|
#[get("/privacy")]
|
|
|
pub async fn privacy() -> Option<NamedFile> {
|
|
|
|
|
|
NamedFile::open("templates/privacy-policy.html").await.ok()
|
|
|
|
|
|
|
|
|
pub async fn privacy() -> Result<NamedFile, NotFound<String>> {
|
|
|
|
|
|
NamedFile::open("templates/privacy-policy.html").await.map_err(|e|NotFound(e.to_string()))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[get("/test")]
|
|
|
|
|
|
// Render Template Responder
|
|
|
|
|
|
pub fn test() -> Template {
|
|
|
|
|
|
println!("{}", &config::init_lang());
|
|
|
|
|
|
Template::render("test", templates::MyStruct{
|
|
|
|
|
|
title: "test",
|
|
|
|
|
|
lang: "en",
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|