MeiliSearch/meilisearch-http/src/lib.rs

59 lines
1.9 KiB
Rust
Raw Normal View History

2020-12-12 13:32:06 +01:00
pub mod data;
pub mod error;
pub mod helpers;
2021-03-04 11:23:41 +01:00
mod index;
2021-01-13 17:50:36 +01:00
mod index_controller;
2021-03-15 18:11:10 +01:00
pub mod option;
pub mod routes;
2020-12-12 13:32:06 +01:00
pub use self::data::Data;
2021-03-15 18:11:10 +01:00
pub use option::Opt;
2021-03-10 11:56:51 +01:00
#[macro_export]
macro_rules! create_app {
2021-03-15 18:11:10 +01:00
($data:expr, $enable_frontend:expr) => {{
use actix_cors::Cors;
use actix_web::middleware::TrailingSlash;
use actix_web::App;
use actix_web::{middleware, web};
use meilisearch_http::error::payload_error_handler;
use meilisearch_http::routes::*;
2021-03-10 11:56:51 +01:00
2021-03-15 18:11:10 +01:00
let app = App::new()
.data($data.clone())
.app_data(
web::JsonConfig::default()
2021-03-10 11:56:51 +01:00
.limit($data.http_payload_size_limit())
.content_type(|_mime| true) // Accept all mime types
.error_handler(|err, _req| payload_error_handler(err).into()),
2021-03-15 18:11:10 +01:00
)
.app_data(
web::QueryConfig::default()
.error_handler(|err, _req| payload_error_handler(err).into()),
)
.configure(document::services)
.configure(index::services)
.configure(search::services)
.configure(settings::services)
.configure(synonym::services)
.configure(health::services)
.configure(stats::services)
.configure(key::services);
//.configure(routes::dump::services);
let app = if $enable_frontend {
app.service(load_html).service(load_css)
} else {
2021-03-19 11:34:54 +01:00
app.service(running)
2021-03-15 18:11:10 +01:00
};
app.wrap(
Cors::default()
2021-03-10 11:56:51 +01:00
.send_wildcard()
.allowed_headers(vec!["content-type", "x-meili-api-key"])
2021-03-15 18:11:10 +01:00
.max_age(86_400), // 24h
)
.wrap(middleware::Logger::default())
.wrap(middleware::Compress::default())
.wrap(middleware::NormalizePath::new(TrailingSlash::Trim))
}};
2021-03-10 11:56:51 +01:00
}