meilisearch/src/lib.rs

64 lines
1.7 KiB
Rust
Raw Normal View History

2020-12-12 20:32:06 +08:00
#![allow(clippy::or_fun_call)]
pub mod data;
pub mod error;
pub mod helpers;
pub mod option;
pub mod routes;
2020-12-22 21:02:41 +08:00
mod updates;
//pub mod analytics;
//pub mod snapshot;
//pub mod dump;
2020-12-12 20:32:06 +08:00
use actix_http::Error;
use actix_service::ServiceFactory;
use actix_web::{dev, web, App};
pub use option::Opt;
pub use self::data::Data;
2020-12-22 21:02:41 +08:00
use self::error::payload_error_handler;
2020-12-12 20:32:06 +08:00
pub fn create_app(
data: &Data,
enable_frontend: bool,
) -> App<
impl ServiceFactory<
Config = (),
Request = dev::ServiceRequest,
Response = dev::ServiceResponse<actix_http::body::Body>,
Error = Error,
InitError = (),
>,
actix_http::body::Body,
> {
let app = App::new()
.data(data.clone())
.app_data(
web::JsonConfig::default()
2020-12-23 00:53:13 +08:00
.limit(data.http_payload_size_limit())
2020-12-12 20:32:06 +08:00
.content_type(|_mime| true) // Accept all mime types
.error_handler(|err, _req| payload_error_handler(err).into()),
)
.app_data(
web::QueryConfig::default()
.error_handler(|err, _req| payload_error_handler(err).into())
)
.configure(routes::document::services)
.configure(routes::index::services)
.configure(routes::search::services)
2021-01-01 23:59:49 +08:00
.configure(routes::settings::services)
2020-12-12 20:32:06 +08:00
.configure(routes::stop_words::services)
.configure(routes::synonym::services)
.configure(routes::health::services)
.configure(routes::stats::services)
2020-12-22 21:02:41 +08:00
.configure(routes::key::services);
//.configure(routes::dump::services);
2020-12-12 20:32:06 +08:00
if enable_frontend {
app
.service(routes::load_html)
.service(routes::load_css)
} else {
app
}
}