mirror of
https://github.com/agersant/polaris
synced 2024-12-02 17:49:10 +00:00
Shut down server when quitting
This commit is contained in:
parent
f82ddc484c
commit
e631138562
1 changed files with 22 additions and 21 deletions
43
src/main.rs
43
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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue