mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-12-02 01:55:03 +08:00
Merge #1097
1097: disable frontend in production r=LegendreM a=MarinPostma disable frontend in production as per #411 and https://github.com/meilisearch/specifications/blob/master/text/0001-frontend-disable-prod.md Co-authored-by: mpostma <postma.marin@protonmail.com>
This commit is contained in:
commit
65079f5e2e
@ -24,6 +24,7 @@ use self::error::{payload_error_handler, ResponseError};
|
|||||||
|
|
||||||
pub fn create_app(
|
pub fn create_app(
|
||||||
data: &Data,
|
data: &Data,
|
||||||
|
enable_frontend: bool,
|
||||||
) -> App<
|
) -> App<
|
||||||
impl ServiceFactory<
|
impl ServiceFactory<
|
||||||
Config = (),
|
Config = (),
|
||||||
@ -34,7 +35,7 @@ pub fn create_app(
|
|||||||
>,
|
>,
|
||||||
actix_http::body::Body,
|
actix_http::body::Body,
|
||||||
> {
|
> {
|
||||||
App::new()
|
let app = App::new()
|
||||||
.data(data.clone())
|
.data(data.clone())
|
||||||
.app_data(
|
.app_data(
|
||||||
web::JsonConfig::default()
|
web::JsonConfig::default()
|
||||||
@ -46,8 +47,6 @@ pub fn create_app(
|
|||||||
web::QueryConfig::default()
|
web::QueryConfig::default()
|
||||||
.error_handler(|err, _req| payload_error_handler(err).into())
|
.error_handler(|err, _req| payload_error_handler(err).into())
|
||||||
)
|
)
|
||||||
.service(routes::load_html)
|
|
||||||
.service(routes::load_css)
|
|
||||||
.configure(routes::document::services)
|
.configure(routes::document::services)
|
||||||
.configure(routes::index::services)
|
.configure(routes::index::services)
|
||||||
.configure(routes::search::services)
|
.configure(routes::search::services)
|
||||||
@ -57,7 +56,14 @@ pub fn create_app(
|
|||||||
.configure(routes::health::services)
|
.configure(routes::health::services)
|
||||||
.configure(routes::stats::services)
|
.configure(routes::stats::services)
|
||||||
.configure(routes::key::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> {
|
pub fn index_update_callback_txn(index: Index, index_uid: &str, data: &Data, mut writer: &mut MainWriter) -> Result<(), String> {
|
||||||
|
@ -80,8 +80,9 @@ async fn main() -> Result<(), MainError> {
|
|||||||
|
|
||||||
print_launch_resume(&opt, &data);
|
print_launch_resume(&opt, &data);
|
||||||
|
|
||||||
|
let enable_frontend = opt.env != "production";
|
||||||
let http_server = HttpServer::new(move || {
|
let http_server = HttpServer::new(move || {
|
||||||
create_app(&data)
|
create_app(&data, enable_frontend)
|
||||||
.wrap(
|
.wrap(
|
||||||
Cors::new()
|
Cors::new()
|
||||||
.send_wildcard()
|
.send_wildcard()
|
||||||
|
@ -160,7 +160,7 @@ impl Server {
|
|||||||
eprintln!("get_request: {}", url);
|
eprintln!("get_request: {}", url);
|
||||||
|
|
||||||
let mut app =
|
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 req = test::TestRequest::get().uri(url).to_request();
|
||||||
let res = test::call_service(&mut app, req).await;
|
let res = test::call_service(&mut app, req).await;
|
||||||
@ -175,7 +175,7 @@ impl Server {
|
|||||||
eprintln!("post_request: {}", url);
|
eprintln!("post_request: {}", url);
|
||||||
|
|
||||||
let mut app =
|
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()
|
let req = test::TestRequest::post()
|
||||||
.uri(url)
|
.uri(url)
|
||||||
@ -204,7 +204,7 @@ impl Server {
|
|||||||
eprintln!("put_request: {}", url);
|
eprintln!("put_request: {}", url);
|
||||||
|
|
||||||
let mut app =
|
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()
|
let req = test::TestRequest::put()
|
||||||
.uri(url)
|
.uri(url)
|
||||||
@ -233,7 +233,7 @@ impl Server {
|
|||||||
eprintln!("delete_request: {}", url);
|
eprintln!("delete_request: {}", url);
|
||||||
|
|
||||||
let mut app =
|
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 req = test::TestRequest::delete().uri(url).to_request();
|
||||||
let res = test::call_service(&mut app, req).await;
|
let res = test::call_service(&mut app, req).await;
|
||||||
|
Loading…
Reference in New Issue
Block a user