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() {
|
fn main() {
|
||||||
|
|
||||||
println!("Spawning server thread");
|
println!("Starting up server");
|
||||||
std::thread::spawn(move || {
|
let mut api_chain;
|
||||||
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 mut collection = collection::Collection::new();
|
let collection = Arc::new(Mutex::new(collection));
|
||||||
collection.load_config(Path::new("Polaris.toml")).unwrap();
|
api_handler = api::get_api_handler(collection);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
api_chain = Chain::new(api_handler);
|
||||||
|
|
||||||
let mut mount = Mount::new();
|
let auth_secret = std::env::var("POLARIS_SECRET")
|
||||||
mount.mount("/api/", api_chain);
|
.expect("Environment variable POLARIS_SECRET must be set");
|
||||||
mount.mount("/", Static::new(Path::new("web")));
|
let cookie_middleware = oven::new(auth_secret.into_bytes());
|
||||||
Iron::new(mount).http("localhost:3000").unwrap();
|
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();
|
ui::run();
|
||||||
|
|
||||||
|
println!("Shutting down server");
|
||||||
|
server.close().unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue