This commit is contained in:
marin postma 2021-06-24 16:25:52 +02:00
parent 8e4928c7ea
commit 79fc3bb84e
No known key found for this signature in database
GPG Key ID: 6088B7721C3E39F9
6 changed files with 30 additions and 25 deletions

View File

@ -19,8 +19,8 @@ pub use option::Opt;
use actix_web::web; use actix_web::web;
use extractors::payload::PayloadConfig;
use extractors::authentication::policies::*; use extractors::authentication::policies::*;
use extractors::payload::PayloadConfig;
pub fn configure_data(config: &mut web::ServiceConfig, data: Data) { pub fn configure_data(config: &mut web::ServiceConfig, data: Data) {
let http_payload_size_limit = data.http_payload_size_limit(); let http_payload_size_limit = data.http_payload_size_limit();
@ -42,7 +42,7 @@ pub fn configure_data(config: &mut web::ServiceConfig, data: Data) {
pub fn configure_auth(config: &mut web::ServiceConfig, data: &Data) { pub fn configure_auth(config: &mut web::ServiceConfig, data: &Data) {
let keys = data.api_keys(); let keys = data.api_keys();
let auth_config = if let Some(ref master_key) = keys.master { let auth_config = if let Some(ref master_key) = keys.master {
let private_key = keys.private.as_ref().unwrap(); let private_key = keys.private.as_ref().unwrap();
let public_key = keys.public.as_ref().unwrap(); let public_key = keys.public.as_ref().unwrap();
let mut policies = init_policies!(Public, Private, Admin); let mut policies = init_policies!(Public, Private, Admin);
@ -62,8 +62,8 @@ pub fn configure_auth(config: &mut web::ServiceConfig, data: &Data) {
#[cfg(feature = "mini-dashboard")] #[cfg(feature = "mini-dashboard")]
pub fn dashboard(config: &mut web::ServiceConfig, enable_frontend: bool) { pub fn dashboard(config: &mut web::ServiceConfig, enable_frontend: bool) {
use actix_web_static_files::Resource;
use actix_web::HttpResponse; use actix_web::HttpResponse;
use actix_web_static_files::Resource;
mod generated { mod generated {
include!(concat!(env!("OUT_DIR"), "/generated.rs")); include!(concat!(env!("OUT_DIR"), "/generated.rs"));
@ -71,22 +71,24 @@ pub fn dashboard(config: &mut web::ServiceConfig, enable_frontend: bool) {
if enable_frontend { if enable_frontend {
let generated = generated::generate(); let generated = generated::generate();
let mut scope = web::scope("/"); let mut scope = web::scope("/");
// Generate routes for mini-dashboard assets // Generate routes for mini-dashboard assets
for (path, resource) in generated.into_iter() { for (path, resource) in generated.into_iter() {
let Resource {mime_type, data, ..} = resource; let Resource {
// Redirect index.html to / mime_type, data, ..
if path == "index.html" { } = resource;
config.service(web::resource("/").route(web::get().to(move || { // Redirect index.html to /
HttpResponse::Ok().content_type(mime_type).body(data) if path == "index.html" {
}))); config.service(web::resource("/").route(
} else { web::get().to(move || HttpResponse::Ok().content_type(mime_type).body(data)),
scope = scope.service(web::resource(path).route(web::get().to(move || { ));
HttpResponse::Ok().content_type(mime_type).body(data) } else {
}))); scope = scope.service(web::resource(path).route(
} web::get().to(move || HttpResponse::Ok().content_type(mime_type).body(data)),
));
} }
config.service(scope); }
config.service(scope);
} else { } else {
config.route("/", web::get().to(routes::running)); config.route("/", web::get().to(routes::running));
} }
@ -105,7 +107,7 @@ macro_rules! create_app {
use actix_web::App; use actix_web::App;
use actix_web::{middleware, web}; use actix_web::{middleware, web};
use meilisearch_http::routes::*; use meilisearch_http::routes::*;
use meilisearch_http::{configure_data, dashboard, configure_auth}; use meilisearch_http::{configure_auth, configure_data, dashboard};
App::new() App::new()
.configure(|s| configure_data(s, $data.clone())) .configure(|s| configure_data(s, $data.clone()))

View File

@ -1,8 +1,8 @@
use actix_web::{web, HttpResponse}; use actix_web::{web, HttpResponse};
use serde::Serialize; use serde::Serialize;
use crate::extractors::authentication::{policies::*, GuardedData};
use crate::Data; use crate::Data;
use crate::extractors::authentication::{GuardedData, policies::*};
pub fn services(cfg: &mut web::ServiceConfig) { pub fn services(cfg: &mut web::ServiceConfig) {
cfg.route("/keys", web::get().to(list)); cfg.route("/keys", web::get().to(list));

View File

@ -6,10 +6,10 @@ use serde::Deserialize;
use serde_json::Value; use serde_json::Value;
use crate::error::ResponseError; use crate::error::ResponseError;
use crate::extractors::authentication::{policies::*, GuardedData};
use crate::index::{default_crop_length, SearchQuery, DEFAULT_SEARCH_LIMIT}; use crate::index::{default_crop_length, SearchQuery, DEFAULT_SEARCH_LIMIT};
use crate::routes::IndexParam; use crate::routes::IndexParam;
use crate::Data; use crate::Data;
use crate::extractors::authentication::{GuardedData, policies::*};
pub fn services(cfg: &mut web::ServiceConfig) { pub fn services(cfg: &mut web::ServiceConfig) {
cfg.service( cfg.service(

View File

@ -1,7 +1,7 @@
use log::debug; use log::debug;
use actix_web::{web, HttpResponse}; use actix_web::{web, HttpResponse};
use crate::extractors::authentication::{GuardedData, policies::*}; use crate::extractors::authentication::{policies::*, GuardedData};
use crate::index::Settings; use crate::index::Settings;
use crate::Data; use crate::Data;
use crate::{error::ResponseError, index::Unchecked}; use crate::{error::ResponseError, index::Unchecked};

View File

@ -3,7 +3,7 @@ use actix_web::{web, HttpResponse};
use serde::Serialize; use serde::Serialize;
use crate::error::ResponseError; use crate::error::ResponseError;
use crate::extractors::authentication::{GuardedData, policies::*}; use crate::extractors::authentication::{policies::*, GuardedData};
use crate::routes::IndexParam; use crate::routes::IndexParam;
use crate::Data; use crate::Data;

View File

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use serde_json::{Value, json}; use serde_json::{json, Value};
use crate::common::Server; use crate::common::Server;
@ -11,7 +11,10 @@ static DEFAULT_SETTINGS_VALUES: Lazy<HashMap<&'static str, Value>> = Lazy::new(|
map.insert("searchable_attributes", json!(["*"])); map.insert("searchable_attributes", json!(["*"]));
map.insert("filterable_attributes", json!([])); map.insert("filterable_attributes", json!([]));
map.insert("distinct_attribute", json!(Value::Null)); map.insert("distinct_attribute", json!(Value::Null));
map.insert("ranking_rules", json!(["words", "typo", "proximity", "attribute", "exactness"])); map.insert(
"ranking_rules",
json!(["words", "typo", "proximity", "attribute", "exactness"]),
);
map.insert("stop_words", json!([])); map.insert("stop_words", json!([]));
map.insert("synonyms", json!({})); map.insert("synonyms", json!({}));
map map