This commit is contained in:
2020-10-27 01:41:50 +01:00
parent c709ca2166
commit 11aa131186
16 changed files with 2706 additions and 5 deletions

View File

@ -1,3 +1,46 @@
fn main() {
println!("Hello, world!");
#![feature(decl_macro)]
mod database;
mod routes;
mod status_json;
use std::{io, env};
use dotenv::dotenv;
use rocket_contrib::templates::Template;
use rocket_contrib::serve::StaticFiles;
use handlebars::handlebars_helper;
fn main() -> io::Result<()> {
dotenv().ok();
let db_path = env::var("DB_PATH").expect("DB_PATH not set");
let sled = sled::open(db_path)?;
handlebars_helper!(pretty_datetime: |dt: str| {
let date = dt.trim_end_matches(|c| c != 'T').trim_end_matches('T');
let time = dt.trim_start_matches(|c| c != 'T').trim_start_matches('T')
.trim_end_matches(|c| c != ':').trim_end_matches(':');
format!("{} {}", date, time)
});
let rocket = rocket::ignite()
.attach(Template::custom(|engines| {
engines.handlebars.register_helper("pretty_datetime", Box::new(pretty_datetime));
}))
.manage(sled)
.mount("/static", StaticFiles::from("static"))
.mount(
"/",
rocket::routes![
routes::index,
routes::history,
routes::create_category,
routes::toggle_category,
],
);
rocket.launch();
Ok(())
}