From 1dc202f50e35c6ae685b053b7529283af8165a14 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Thu, 27 Oct 2022 01:09:45 +0200 Subject: Indexer: Setup permissive CORS --- Cargo.lock | 16 ++++++++++++++++ indexer/Cargo.toml | 3 ++- indexer/src/main.rs | 3 +++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 8686540..63e25f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,21 @@ dependencies = [ "tokio-util 0.7.4", ] +[[package]] +name = "actix-cors" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "684a6ce1562a5fcca49bc9302896c63547eea78a1e405e837e7416affd8b6eb9" +dependencies = [ + "actix-utils", + "actix-web", + "derive_more", + "futures-util", + "log", + "once_cell", + "smallvec", +] + [[package]] name = "actix-http" version = "3.2.2" @@ -1097,6 +1112,7 @@ dependencies = [ name = "indexer" version = "0.1.0" dependencies = [ + "actix-cors", "actix-web", "html2text", "rand 0.7.3", diff --git a/indexer/Cargo.toml b/indexer/Cargo.toml index 97b8497..32355db 100644 --- a/indexer/Cargo.toml +++ b/indexer/Cargo.toml @@ -6,7 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -actix-web = "*" +actix-web = "4.2.1" +actix-cors = "0.6.3" serde = { version = "1.0", features = ["derive"] } scraper = "0.12.0" html2text = "0.4.3" diff --git a/indexer/src/main.rs b/indexer/src/main.rs index 44dbd1b..4ea81ae 100644 --- a/indexer/src/main.rs +++ b/indexer/src/main.rs @@ -1,3 +1,4 @@ +use actix_cors::Cors; use actix_web::{get, post, web, App, HttpServer, Responder}; use rand::Rng; use serde::{Deserialize, Serialize}; @@ -42,7 +43,9 @@ async fn serve_http_endpoint(address: &str, port: u16) -> std::io::Result<()> { database: Mutex::new(HashMap::new()), }); HttpServer::new(move || { + let cors = Cors::permissive(); App::new() + .wrap(cors) .app_data(shared_state.clone()) .service(search) .service(add_resource) -- cgit 1.4.1