2020-12-12 20:32:06 +08:00
|
|
|
pub mod data;
|
2021-06-15 23:55:27 +08:00
|
|
|
#[macro_use]
|
2020-12-12 20:32:06 +08:00
|
|
|
pub mod error;
|
|
|
|
pub mod helpers;
|
2021-03-04 18:23:41 +08:00
|
|
|
mod index;
|
2021-01-14 00:50:36 +08:00
|
|
|
mod index_controller;
|
2021-03-16 01:11:10 +08:00
|
|
|
pub mod option;
|
|
|
|
pub mod routes;
|
2020-12-12 20:32:06 +08:00
|
|
|
|
2021-06-16 23:12:49 +08:00
|
|
|
#[cfg(all(not(debug_assertions), feature = "analytics"))]
|
2021-06-15 21:36:30 +08:00
|
|
|
pub mod analytics;
|
|
|
|
|
2020-12-12 20:32:06 +08:00
|
|
|
pub use self::data::Data;
|
2021-03-16 01:11:10 +08:00
|
|
|
pub use option::Opt;
|
2021-03-10 18:56:51 +08:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! create_app {
|
2021-03-16 01:11:10 +08: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 18:56:51 +08:00
|
|
|
|
2021-04-21 19:49:21 +08:00
|
|
|
#[cfg(feature = "mini-dashboard")]
|
|
|
|
use actix_web_static_files::ResourceFiles;
|
|
|
|
|
|
|
|
#[cfg(feature = "mini-dashboard")]
|
|
|
|
mod dashboard {
|
|
|
|
include!(concat!(env!("OUT_DIR"), "/generated.rs"));
|
|
|
|
}
|
|
|
|
|
2021-03-16 01:11:10 +08:00
|
|
|
let app = App::new()
|
|
|
|
.data($data.clone())
|
|
|
|
.app_data(
|
|
|
|
web::JsonConfig::default()
|
2021-03-10 18:56:51 +08: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-16 01:11:10 +08: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(health::services)
|
|
|
|
.configure(stats::services)
|
2021-05-05 20:11:56 +08:00
|
|
|
.configure(key::services)
|
|
|
|
.configure(dump::services);
|
2021-04-21 19:49:21 +08:00
|
|
|
#[cfg(feature = "mini-dashboard")]
|
2021-03-16 01:11:10 +08:00
|
|
|
let app = if $enable_frontend {
|
2021-04-21 19:49:21 +08:00
|
|
|
let generated = dashboard::generate();
|
|
|
|
let service = ResourceFiles::new("/", generated);
|
|
|
|
app.service(service)
|
2021-03-16 01:11:10 +08:00
|
|
|
} else {
|
2021-03-19 18:34:54 +08:00
|
|
|
app.service(running)
|
2021-03-16 01:11:10 +08:00
|
|
|
};
|
2021-04-21 19:49:21 +08:00
|
|
|
|
|
|
|
#[cfg(not(feature = "mini-dashboard"))]
|
|
|
|
let app = app.service(running);
|
|
|
|
|
2021-03-16 01:11:10 +08:00
|
|
|
app.wrap(
|
|
|
|
Cors::default()
|
2021-05-31 22:03:39 +08:00
|
|
|
.send_wildcard()
|
|
|
|
.allowed_headers(vec!["content-type", "x-meili-api-key"])
|
|
|
|
.allow_any_origin()
|
|
|
|
.allow_any_method()
|
|
|
|
.max_age(86_400), // 24h
|
2021-03-16 01:11:10 +08:00
|
|
|
)
|
|
|
|
.wrap(middleware::Logger::default())
|
|
|
|
.wrap(middleware::Compress::default())
|
|
|
|
.wrap(middleware::NormalizePath::new(TrailingSlash::Trim))
|
|
|
|
}};
|
2021-03-10 18:56:51 +08:00
|
|
|
}
|