use std::path::Path; use rocket::{ State, fairing::AdHoc, fs::{FileServer, NamedFile}, get, launch, routes, serde::{Deserialize, Serialize}, }; use rocket_dyn_templates::{Template, context}; #[derive(Debug, Deserialize, Serialize)] #[serde(crate = "rocket::serde")] struct Config { pub public_url: String, } #[get("/")] fn index(config: &State) -> Template { Template::render( "index", context! { url: config.public_url.clone(), }, ) } #[get("/dms")] fn dms(config: &State) -> Template { Template::render( "dms", context! { url: config.public_url.clone(), }, ) } #[get("/carrd")] fn carrd(config: &State) -> Template { Template::render( "carrd", context! { url: config.public_url.clone(), }, ) } #[get("/favicon.ico")] async fn icon() -> Option { NamedFile::open(Path::new("./static/favicon.ico")) .await .ok() } #[launch] fn rocket() -> _ { rocket::build() .mount("/", routes![index, dms, carrd, icon]) .mount("/assets", FileServer::from("./static")) .attach(Template::fairing()) .attach(AdHoc::config::()) }