<commit_before>extern crate core;
extern crate iron;
extern crate mount;
extern crate oven;
extern crate params;
extern crate regex;
extern crate id3;
extern crate rustc_serialize;
extern crate staticfile;
extern crate toml;
extern crate url;

#[cfg(windows)]
extern crate uuid;
#[cfg(windows)]
extern crate winapi;
#[cfg(windows)]
extern crate kernel32;
#[cfg(windows)]
extern crate shell32;
#[cfg(windows)]
extern crate user32;

use std::path::Path;
use std::sync::Arc;
use std::sync::Mutex;

use iron::prelude::*;
use mount::Mount;
use staticfile::Static;

mod api;
mod collection;
mod error;
mod ui;
mod vfs;

fn main() {

    println!("Spawning server thread");
    std::thread::spawn(move || {
        let mut api_chain;
        {
            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 mount = Mount::new();
        mount.mount("/api/", api_chain);
        mount.mount("/", Static::new(Path::new("web")));
        Iron::new(mount).http("localhost:3000").unwrap();
    });

    ui::run();
}<commit_msg>Shut down server when quitting<commit_after>extern crate core;
extern crate iron;
extern crate mount;
extern crate oven;
extern crate params;
extern crate regex;
extern crate id3;
extern crate rustc_serialize;
extern crate staticfile;
extern crate toml;
extern crate url;

#[cfg(windows)]
extern crate uuid;
#[cfg(windows)]
extern crate winapi;
#[cfg(windows)]
extern crate kernel32;
#[cfg(windows)]
extern crate shell32;
#[cfg(windows)]
extern crate user32;

use std::path::Path;
use std::sync::Arc;
use std::sync::Mutex;

use iron::prelude::*;
use mount::Mount;
use staticfile::Static;

mod api;
mod collection;
mod error;
mod ui;
mod vfs;

fn main() {

    println!("Starting up server");
    let mut api_chain;
    {
        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 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();
}
{'fraction_non_alphanumeric': 0.1419695557626592, 'fraction_numerical': 0.006834420627524076, 'mean_word_length': 3.447513812154696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6663191', 'n_tokens_mistral': 1018, 'n_tokens_neox': 975, 'n_words': 252}