2017-12-06 15:29:10 +01:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(rocket_codegen)]
|
|
|
|
|
2017-12-17 13:19:27 +01:00
|
|
|
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;
|
2018-03-09 22:24:04 +01:00
|
|
|
extern crate toml;
|
2017-12-06 15:29:10 +01:00
|
|
|
|
2017-12-30 22:06:48 +01:00
|
|
|
mod handlers;
|
2017-12-30 22:23:16 +01:00
|
|
|
mod models;
|
2017-12-06 15:38:07 +01:00
|
|
|
|
2017-12-30 22:06:48 +01:00
|
|
|
use rocket::Rocket;
|
2018-03-09 22:24:04 +01:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::prelude::*;
|
2017-12-27 17:33:28 +01:00
|
|
|
use std::sync::RwLock;
|
|
|
|
|
2018-01-26 21:18:04 +01:00
|
|
|
type NoteStore = RwLock<Vec<models::note::Note>>;
|
2017-12-30 22:23:16 +01:00
|
|
|
|
2018-03-09 22:24:04 +01:00
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
struct Config {
|
|
|
|
title: String,
|
|
|
|
}
|
|
|
|
|
2018-01-26 21:18:04 +01:00
|
|
|
fn rocket(notes_path: Option<&str>) -> Rocket {
|
2018-03-09 22:24:04 +01:00
|
|
|
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");
|
|
|
|
|
2018-01-26 21:18:04 +01:00
|
|
|
let notes = models::note::Note::load_all(notes_path);
|
2018-03-09 22:24:04 +01:00
|
|
|
|
2017-12-06 15:29:10 +01:00
|
|
|
rocket::ignite()
|
2018-01-26 21:18:04 +01:00
|
|
|
.manage(RwLock::new(notes))
|
2018-03-09 22:24:04 +01:00
|
|
|
.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
|
|
|
|
],
|
|
|
|
)
|
2017-12-30 22:06:48 +01:00
|
|
|
.attach(rocket_contrib::Template::fairing())
|
2017-12-06 15:38:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2018-01-01 18:36:58 +01:00
|
|
|
rocket(None).launch();
|
2017-12-06 15:29:10 +01:00
|
|
|
}
|