2019-03-27 16:50:54 -04:00
|
|
|
#[macro_use] extern crate diesel;
|
|
|
|
#[macro_use] extern crate mime;
|
2019-03-26 16:00:35 -04:00
|
|
|
|
2019-03-28 17:24:19 -04:00
|
|
|
use env_logger;
|
|
|
|
|
|
|
|
use handlebars as hbs;
|
|
|
|
use handlebars_iron as hbi;
|
|
|
|
|
|
|
|
use hbs::Handlebars;
|
|
|
|
use hbi::{DirectorySource, HandlebarsEngine};
|
|
|
|
|
|
|
|
use iron::prelude::{Chain, Iron};
|
|
|
|
use std::error::Error;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use media_collection_crud::{chain, db};
|
2019-03-26 16:44:22 -04:00
|
|
|
|
2019-03-28 17:24:19 -04:00
|
|
|
fn init_templating() -> Chain {
|
|
|
|
let views_ext = ".hbs";
|
|
|
|
let views_path = "./src/views";
|
2019-03-26 16:44:22 -04:00
|
|
|
|
2019-03-28 17:24:19 -04:00
|
|
|
let hbs = Handlebars::new();
|
|
|
|
let mut hbse = HandlebarsEngine::from(hbs);
|
|
|
|
// TODO: Investigate serving the templates out of the binary using include_string!
|
|
|
|
hbse.add(Box::new(
|
|
|
|
DirectorySource::new(views_path, views_ext)
|
|
|
|
));
|
2019-03-26 16:00:35 -04:00
|
|
|
|
2019-03-28 17:24:19 -04:00
|
|
|
if let Err(r) = hbse.reload() {
|
|
|
|
panic!("{:?}", r.description());
|
|
|
|
}
|
|
|
|
|
|
|
|
let hbse_ref = Arc::new(hbse);
|
|
|
|
if cfg!(debug_assertions) {
|
|
|
|
println!("Templates are being watched.");
|
|
|
|
use hbi::Watchable;
|
|
|
|
hbse_ref.watch(views_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut chain = chain::init();
|
|
|
|
chain.link_after(hbse_ref);
|
|
|
|
|
|
|
|
chain
|
2019-03-26 16:00:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2019-03-28 17:24:19 -04:00
|
|
|
env_logger::init();
|
|
|
|
db::establish_connection();
|
|
|
|
|
|
|
|
let port = 8000;
|
|
|
|
let bind_addr = format!("localhost:{}", port);
|
2019-03-27 16:50:54 -04:00
|
|
|
|
2019-03-28 17:24:19 -04:00
|
|
|
let _server_guard = Iron::new(init_templating())
|
|
|
|
.http(bind_addr.as_str())
|
2019-03-26 16:00:35 -04:00
|
|
|
.unwrap();
|
|
|
|
}
|