add middleware

This commit is contained in:
Quentin de Quelen 2020-04-10 19:40:43 +02:00 committed by qdequele
parent 6a1f73a304
commit 5fed155f15
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
3 changed files with 24 additions and 3 deletions

13
Cargo.lock generated
View File

@ -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",

View File

@ -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]

View File

@ -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)