rocket-pinboard/src/main.rs

63 lines
1.5 KiB
Rust
Raw Normal View History

2017-12-06 15:29:10 +01:00
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate comrak;
extern crate glob;
extern crate inflector;
2017-12-06 15:29:10 +01:00
extern crate rocket;
2017-12-06 16:47:55 +01:00
extern crate rocket_contrib;
2018-02-15 20:49:42 +01:00
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_json;
extern crate toml;
2017-12-06 15:29:10 +01:00
mod handlers;
mod models;
use rocket::Rocket;
use std::fs::File;
use std::io::prelude::*;
use std::sync::RwLock;
type NoteStore = RwLock<Vec<models::note::Note>>;
#[derive(Debug, Deserialize)]
struct Config {
title: String,
}
fn rocket(notes_path: Option<&str>) -> Rocket {
let mut config_data = String::new();
let mut config_file = File::open("config.toml").expect("Cannot find config file: config.toml");
config_file
.read_to_string(&mut config_data)
.expect("Cannot read config file: config.toml");
let config: Config =
toml::from_str(&config_data).expect("Cannot parse config file: config.toml");
let notes = models::note::Note::load_all(notes_path);
2017-12-06 15:29:10 +01:00
rocket::ignite()
.manage(RwLock::new(notes))
.manage(config)
2018-02-15 20:49:42 +01:00
.mount(
"/",
routes![handlers::home::index, handlers::static_files::all],
)
.mount(
"/notes",
routes![
handlers::note::index,
handlers::note::show_html,
handlers::note::show_json,
handlers::note::update
],
)
.attach(rocket_contrib::Template::fairing())
}
fn main() {
rocket(None).launch();
2017-12-06 15:29:10 +01:00
}