From 9db70852de30923c87c062238192da9b53dd5dcf Mon Sep 17 00:00:00 2001 From: Stephan Vedder Date: Tue, 27 Feb 2024 11:43:53 +0100 Subject: [PATCH] Add CORS policy --- Cargo.lock | 16 ++++++++++++++++ examples/simple_server/Cargo.toml | 1 + examples/simple_server/src/main.rs | 7 +++++-- server/src/filter.rs | 1 - server/src/multipart/builder.rs | 1 - server/src/wado.rs | 4 +--- 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4725d89..a6f4141 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,21 @@ dependencies = [ "tracing", ] +[[package]] +name = "actix-cors" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9e772b3bcafe335042b5db010ab7c09013dad6eac4915c91d8d50902769f331" +dependencies = [ + "actix-utils", + "actix-web", + "derive_more", + "futures-util", + "log", + "once_cell", + "smallvec", +] + [[package]] name = "actix-http" version = "3.6.0" @@ -1759,6 +1774,7 @@ checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" name = "simple_server" version = "0.1.0" dependencies = [ + "actix-cors", "actix-web", "dicom", "dicom-object", diff --git a/examples/simple_server/Cargo.toml b/examples/simple_server/Cargo.toml index 37430a6..50bdc1a 100644 --- a/examples/simple_server/Cargo.toml +++ b/examples/simple_server/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +actix-cors = "0.7.0" actix-web = "4.5.1" dicom = "0.6.3" dicom-object = "0.6.3" diff --git a/examples/simple_server/src/main.rs b/examples/simple_server/src/main.rs index b1c8fd5..1976f85 100644 --- a/examples/simple_server/src/main.rs +++ b/examples/simple_server/src/main.rs @@ -1,5 +1,4 @@ -use std::{env, fs}; - +use actix_cors::Cors; use actix_web::{middleware, web, App, HttpServer}; use dicom::{ core::{DataElement, PrimitiveValue}, @@ -12,6 +11,7 @@ use dicomweb_server::{ INSTANCE_TAGS, SERIES_TAGS, STUDY_TAGS, }; use itertools::Itertools; +use std::{env, fs}; use walkdir::WalkDir; const DATA_DIR: &str = "data"; @@ -352,7 +352,10 @@ async fn main() -> std::io::Result<()> { env_logger::init(); HttpServer::new(|| { + let cors = Cors::default().allow_any_origin(); + App::new() + .wrap(cors) .wrap(middleware::Compress::default()) .app_data(web::Data::new(dicomweb_server::DicomWebServer { search_instances: search_instances, diff --git a/server/src/filter.rs b/server/src/filter.rs index b444263..d8ce980 100644 --- a/server/src/filter.rs +++ b/server/src/filter.rs @@ -1,4 +1,3 @@ - use dicom_object::InMemDicomObject; use crate::QidoStudyQuery; diff --git a/server/src/multipart/builder.rs b/server/src/multipart/builder.rs index bd9e414..8120cc7 100644 --- a/server/src/multipart/builder.rs +++ b/server/src/multipart/builder.rs @@ -1,4 +1,3 @@ - use std::io::{self, Read, Write}; use uuid::Uuid; diff --git a/server/src/wado.rs b/server/src/wado.rs index 1895452..52a8d9f 100644 --- a/server/src/wado.rs +++ b/server/src/wado.rs @@ -1,6 +1,4 @@ -use std::{ - io::{Write}, -}; +use std::io::Write; use actix_web::{get, web, HttpResponse, Responder};