diff --git a/src/main.rs b/src/main.rs index 2c11b2e..6cb6e8d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(); }