mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Make it a runnable server
This commit is contained in:
parent
f51c49db93
commit
c2a12b661a
2 changed files with 36 additions and 2 deletions
|
@ -1,3 +1,36 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use http::header::HeaderValue;
|
||||
use log::info;
|
||||
use main_error::MainError;
|
||||
use tide::middleware::{CorsMiddleware, CorsOrigin};
|
||||
use tide_log::RequestLogger;
|
||||
|
||||
use meilidb_http::data::Data;
|
||||
use meilidb_http::option::Opt;
|
||||
use meilidb_http::routes;
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
#[global_allocator]
|
||||
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||
|
||||
pub fn main() -> Result<(), MainError> {
|
||||
let opt = Opt::new();
|
||||
|
||||
let data = Data::new(opt.clone());
|
||||
let mut app = tide::App::with_state(data);
|
||||
|
||||
app.middleware(
|
||||
CorsMiddleware::new()
|
||||
.allow_origin(CorsOrigin::from("*"))
|
||||
.allow_methods(HeaderValue::from_static("GET, POST, OPTIONS")),
|
||||
);
|
||||
app.middleware(RequestLogger::new());
|
||||
app.middleware(tide_compression::Compression::new());
|
||||
app.middleware(tide_compression::Decompression::new());
|
||||
|
||||
routes::load_routes(&mut app);
|
||||
|
||||
info!("Server HTTP enabled");
|
||||
app.run(opt.http_addr)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue