From d3e7e18b7dc7fa0aca4372ea35739721e9a06e30 Mon Sep 17 00:00:00 2001 From: mpostma Date: Mon, 23 Nov 2020 13:13:10 +0100 Subject: [PATCH 1/2] disable frontend in production --- meilisearch-http/src/lib.rs | 14 ++++++++++---- meilisearch-http/src/main.rs | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/meilisearch-http/src/lib.rs b/meilisearch-http/src/lib.rs index 68f1e27e4..b5f35f277 100644 --- a/meilisearch-http/src/lib.rs +++ b/meilisearch-http/src/lib.rs @@ -24,6 +24,7 @@ use self::error::{payload_error_handler, ResponseError}; pub fn create_app( data: &Data, + enable_frontend: bool, ) -> App< impl ServiceFactory< Config = (), @@ -34,7 +35,7 @@ pub fn create_app( >, actix_http::body::Body, > { - App::new() + let app = App::new() .data(data.clone()) .app_data( web::JsonConfig::default() @@ -46,8 +47,6 @@ pub fn create_app( web::QueryConfig::default() .error_handler(|err, _req| payload_error_handler(err).into()) ) - .service(routes::load_html) - .service(routes::load_css) .configure(routes::document::services) .configure(routes::index::services) .configure(routes::search::services) @@ -57,7 +56,14 @@ pub fn create_app( .configure(routes::health::services) .configure(routes::stats::services) .configure(routes::key::services) - .configure(routes::dump::services) + .configure(routes::dump::services); + if enable_frontend { + app + .service(routes::load_html) + .service(routes::load_css) + } else { + app + } } pub fn index_update_callback_txn(index: Index, index_uid: &str, data: &Data, mut writer: &mut MainWriter) -> Result<(), String> { diff --git a/meilisearch-http/src/main.rs b/meilisearch-http/src/main.rs index 563f75d2f..41b85d709 100644 --- a/meilisearch-http/src/main.rs +++ b/meilisearch-http/src/main.rs @@ -80,8 +80,9 @@ async fn main() -> Result<(), MainError> { print_launch_resume(&opt, &data); + let enable_frontend = opt.env != "production"; let http_server = HttpServer::new(move || { - create_app(&data) + create_app(&data, enable_frontend) .wrap( Cors::new() .send_wildcard() From cfb21b94e8a6a8902ea671cde62051d1b14e5068 Mon Sep 17 00:00:00 2001 From: mpostma Date: Mon, 30 Nov 2020 15:35:28 +0100 Subject: [PATCH 2/2] fix tests --- meilisearch-http/tests/common.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/meilisearch-http/tests/common.rs b/meilisearch-http/tests/common.rs index 3b875b4d2..30a28bb1b 100644 --- a/meilisearch-http/tests/common.rs +++ b/meilisearch-http/tests/common.rs @@ -160,7 +160,7 @@ impl Server { eprintln!("get_request: {}", url); let mut app = - test::init_service(meilisearch_http::create_app(&self.data).wrap(NormalizePath)).await; + test::init_service(meilisearch_http::create_app(&self.data, true).wrap(NormalizePath)).await; let req = test::TestRequest::get().uri(url).to_request(); let res = test::call_service(&mut app, req).await; @@ -175,7 +175,7 @@ impl Server { eprintln!("post_request: {}", url); let mut app = - test::init_service(meilisearch_http::create_app(&self.data).wrap(NormalizePath)).await; + test::init_service(meilisearch_http::create_app(&self.data, true).wrap(NormalizePath)).await; let req = test::TestRequest::post() .uri(url) @@ -204,7 +204,7 @@ impl Server { eprintln!("put_request: {}", url); let mut app = - test::init_service(meilisearch_http::create_app(&self.data).wrap(NormalizePath)).await; + test::init_service(meilisearch_http::create_app(&self.data, true).wrap(NormalizePath)).await; let req = test::TestRequest::put() .uri(url) @@ -233,7 +233,7 @@ impl Server { eprintln!("delete_request: {}", url); let mut app = - test::init_service(meilisearch_http::create_app(&self.data).wrap(NormalizePath)).await; + test::init_service(meilisearch_http::create_app(&self.data, true).wrap(NormalizePath)).await; let req = test::TestRequest::delete().uri(url).to_request(); let res = test::call_service(&mut app, req).await;