maybemaybemaybe?

This commit is contained in:
hexlocation pc 2024-07-12 18:47:46 +02:00
parent ec0f0777c1
commit 473bd34e4f
9 changed files with 768 additions and 4 deletions

View file

@ -1,12 +1,49 @@
extern crate rocket;
extern crate rocket_dyn_templates;
use rocket::{get,launch, build, routes};
use rocket::fs::FileServer;
use rocket_dyn_templates::{Template, context};
use std::path::Path;
use std::fs::File;
static ASSETS_DIR: &str = "./assets";
static GUEST_MESSAGES: &str = "./guests.json";
fn check_file(path: &str) -> bool {
Path::new(path).exists()
}
#[get("/")]
fn index() -> &'static str {
"Hewwo wowd :3"
fn index() -> Template {
let cx = context! {
hi: "no",
};
Template::render("index", &cx)
}
#[get("/guestbook")]
fn guests() -> Template {
let cx = context! {
messages: [
context!{
name: "hexlocation",
date: "12 Jun.",
body: "<h1>xd1</h1>",
}
]
};
Template::render("guest", &cx)
}
#[launch]
fn rocket() -> _ {
build().mount("/", routes![index])
if !check_file(GUEST_MESSAGES) {
File::create(GUEST_MESSAGES).unwrap();
}
build()
.mount("/", routes![index, guests])
.mount("/assets", FileServer::from(ASSETS_DIR))
.attach(Template::fairing())
}