Shut down server when quitting

This commit is contained in:
Antoine Gersant 2016-09-21 23:44:41 -07:00
parent f82ddc484c
commit e631138562

View file

@ -37,30 +37,31 @@ mod vfs;
fn main() {
println!("Spawning server thread");
std::thread::spawn(move || {
let mut api_chain;
println!("Starting up server");
let mut api_chain;
{
let api_handler;
{
let api_handler;
{
let mut collection = collection::Collection::new();
collection.load_config(Path::new("Polaris.toml")).unwrap();
let collection = Arc::new(Mutex::new(collection));
api_handler = api::get_api_handler(collection);
}
api_chain = Chain::new(api_handler);
let auth_secret = std::env::var("POLARIS_SECRET")
.expect("Environment variable POLARIS_SECRET must be set");
let cookie_middleware = oven::new(auth_secret.into_bytes());
api_chain.link(cookie_middleware);
let mut collection = collection::Collection::new();
collection.load_config(Path::new("Polaris.toml")).unwrap();
let collection = Arc::new(Mutex::new(collection));
api_handler = api::get_api_handler(collection);
}
api_chain = Chain::new(api_handler);
let mut mount = Mount::new();
mount.mount("/api/", api_chain);
mount.mount("/", Static::new(Path::new("web")));
Iron::new(mount).http("localhost:3000").unwrap();
});
let auth_secret = std::env::var("POLARIS_SECRET")
.expect("Environment variable POLARIS_SECRET must be set");
let cookie_middleware = oven::new(auth_secret.into_bytes());
api_chain.link(cookie_middleware);
}
let mut mount = Mount::new();
mount.mount("/api/", api_chain);
mount.mount("/", Static::new(Path::new("web")));
let mut server = Iron::new(mount).http("localhost:3000").unwrap();
ui::run();
println!("Shutting down server");
server.close().unwrap();
}