Just the source code for my personal website.
1use std::path::Path;
2
3use rocket::{
4 State,
5 fairing::AdHoc,
6 fs::{FileServer, NamedFile},
7 get, launch, routes,
8 serde::{Deserialize, Serialize},
9};
10use rocket_dyn_templates::{Template, context};
11
12#[derive(Debug, Deserialize, Serialize)]
13#[serde(crate = "rocket::serde")]
14struct Config {
15 pub public_url: String,
16}
17
18#[get("/")]
19fn index(config: &State<Config>) -> Template {
20 Template::render(
21 "index",
22 context! {
23 url: config.public_url.clone(),
24 },
25 )
26}
27
28#[get("/dms")]
29fn dms(config: &State<Config>) -> Template {
30 Template::render(
31 "dms",
32 context! {
33 url: config.public_url.clone(),
34 },
35 )
36}
37
38#[get("/carrd")]
39fn carrd(config: &State<Config>) -> Template {
40 Template::render(
41 "carrd",
42 context! {
43 url: config.public_url.clone(),
44 },
45 )
46}
47
48#[get("/favicon.ico")]
49async fn icon() -> Option<NamedFile> {
50 NamedFile::open(Path::new("./static/favicon.ico"))
51 .await
52 .ok()
53}
54
55#[launch]
56fn rocket() -> _ {
57 rocket::build()
58 .mount("/", routes![index, dms, carrd, icon])
59 .mount("/assets", FileServer::from("./static"))
60 .attach(Template::fairing())
61 .attach(AdHoc::config::<Config>())
62}