2019-11-21 19:15:33 +01:00
|
|
|
use std::env::VarError::NotPresent;
|
|
|
|
use std::{env, thread};
|
|
|
|
|
2020-01-15 17:10:33 +01:00
|
|
|
use async_std::task;
|
2019-10-31 15:09:23 +01:00
|
|
|
use log::info;
|
|
|
|
use main_error::MainError;
|
2019-11-19 17:09:06 +01:00
|
|
|
use structopt::StructOpt;
|
2020-01-27 18:26:08 +01:00
|
|
|
use tide::middleware::RequestLogger;
|
2019-10-31 15:09:23 +01:00
|
|
|
|
2019-11-26 11:06:55 +01:00
|
|
|
use meilisearch_http::data::Data;
|
|
|
|
use meilisearch_http::option::Opt;
|
|
|
|
use meilisearch_http::routes;
|
|
|
|
use meilisearch_http::routes::index::index_update_callback;
|
2019-10-31 15:09:23 +01:00
|
|
|
|
2020-01-27 19:11:32 +01:00
|
|
|
use cors::Cors;
|
|
|
|
|
2019-11-21 19:15:33 +01:00
|
|
|
mod analytics;
|
2020-01-27 19:11:32 +01:00
|
|
|
mod cors;
|
2019-11-21 19:15:33 +01:00
|
|
|
|
2019-11-25 14:51:47 +01:00
|
|
|
#[cfg(target_os = "linux")]
|
2019-10-31 15:09:23 +01:00
|
|
|
#[global_allocator]
|
|
|
|
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
|
|
|
|
|
|
|
pub fn main() -> Result<(), MainError> {
|
2019-11-11 19:03:38 +01:00
|
|
|
env_logger::init();
|
|
|
|
|
2019-11-19 17:09:06 +01:00
|
|
|
let opt = Opt::from_args();
|
2019-10-31 15:09:23 +01:00
|
|
|
let data = Data::new(opt.clone());
|
2019-11-15 17:33:06 +01:00
|
|
|
|
2019-11-21 19:15:33 +01:00
|
|
|
if env::var("MEILI_NO_ANALYTICS") == Err(NotPresent) {
|
|
|
|
thread::spawn(|| analytics::analytics_sender());
|
|
|
|
}
|
|
|
|
|
2019-11-15 17:33:06 +01:00
|
|
|
let data_cloned = data.clone();
|
|
|
|
data.db.set_update_callback(Box::new(move |name, status| {
|
|
|
|
index_update_callback(name, &data_cloned, status);
|
|
|
|
}));
|
|
|
|
|
2020-01-15 17:10:33 +01:00
|
|
|
let mut app = tide::with_state(data);
|
2019-10-31 15:09:23 +01:00
|
|
|
|
2020-01-27 19:11:32 +01:00
|
|
|
app.middleware(Cors::new());
|
2020-01-27 18:26:08 +01:00
|
|
|
app.middleware(RequestLogger::new());
|
2020-01-15 17:10:33 +01:00
|
|
|
// app.middleware(tide_compression::Compression::new());
|
|
|
|
// app.middleware(tide_compression::Decompression::new());
|
2019-10-31 15:09:23 +01:00
|
|
|
|
|
|
|
routes::load_routes(&mut app);
|
|
|
|
|
|
|
|
info!("Server HTTP enabled");
|
|
|
|
|
2020-01-15 17:10:33 +01:00
|
|
|
task::block_on(async {
|
|
|
|
app.listen(opt.http_addr).await.unwrap();
|
|
|
|
});
|
2019-10-31 15:09:23 +01:00
|
|
|
Ok(())
|
2019-10-31 15:00:36 +01:00
|
|
|
}
|