media-collection-crud/src/main.rs

56 lines
1.1 KiB
Rust

#[macro_use] extern crate diesel;
#[macro_use] extern crate mime;
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};
fn init_templating() -> Chain {
let views_ext = ".hbs";
let views_path = "./src/views";
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)
));
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
}
fn main() {
env_logger::init();
db::establish_connection();
let port = 8000;
let bind_addr = format!("localhost:{}", port);
let _server_guard = Iron::new(init_templating())
.http(bind_addr.as_str())
.unwrap();
}