diff --git a/Cargo.lock b/Cargo.lock index b224ef1e5..fe2b67b7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,6 +34,18 @@ dependencies = [ "trust-dns-resolver", ] +[[package]] +name = "actix-cors" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6206917d5c0fdd79d81cec9ef02d3e802df4abf276d96241e1f595d971e002" +dependencies = [ + "actix-service", + "actix-web", + "derive_more", + "futures", +] + [[package]] name = "actix-files" version = "0.2.1" @@ -1489,6 +1501,7 @@ dependencies = [ name = "meilisearch-http" version = "0.10.1" dependencies = [ + "actix-cors", "actix-files", "actix-http", "actix-rt", diff --git a/meilisearch-http/Cargo.toml b/meilisearch-http/Cargo.toml index cd506c092..ce0bf934b 100644 --- a/meilisearch-http/Cargo.toml +++ b/meilisearch-http/Cargo.toml @@ -45,6 +45,7 @@ actix-rt = "1" actix-web = "2" actix-http = "1" actix-files = "0.2.1" +actix-cors = "0.2.0" tokio = { version = "0.2.0", features = ["macros"] } [dev-dependencies] diff --git a/meilisearch-http/src/main.rs b/meilisearch-http/src/main.rs index e0e19448b..0e43e15f1 100644 --- a/meilisearch-http/src/main.rs +++ b/meilisearch-http/src/main.rs @@ -1,7 +1,7 @@ use std::{env, thread}; -use actix_web::middleware::Logger; -use actix_web::{web, App, HttpServer}; +use actix_cors::Cors; +use actix_web::{web, App, HttpServer, middleware}; use log::info; use main_error::MainError; use meilisearch_http::data::Data; @@ -52,7 +52,14 @@ async fn main() -> Result<(), MainError> { HttpServer::new(move || { App::new() - .wrap(Logger::default()) + .wrap( + Cors::new() + .send_wildcard() + .allowed_header("x-meili-api-key") + .finish() + ) + .wrap(middleware::Logger::default()) + .wrap(middleware::Compress::default()) .app_data(web::Data::new(data.clone())) .service(routes::load_html) .service(routes::load_css)