aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: 042465d65f661acd1e847be01e803b3b77a3b11a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#![feature(proc_macro_hygiene, decl_macro)]

use askama::Template;
use rocket::{
    get,
    http::RawStr,
    routes,
    response::{
        NamedFile,
        content::Html,
    },
};
use std::path::PathBuf;

#[derive(Template)]
#[template(path = "index.html")]
struct IndexTemplate<'a> {
    year: &'a str,
}

#[get("/")]
fn index<'a>() -> Html<String> {
    let t = IndexTemplate { year: "2019" };
    Html(t.render().unwrap())
}

#[get("/<file>", rank = 99)]
fn public_file(file: &RawStr) -> Option<NamedFile> {
    NamedFile::open(PathBuf::from("public/").join(file.as_str())).ok()
}

fn main() {
    rocket::ignite().mount("/", routes![index, public_file]).launch();
}