From 0dd64df5c02dbb9637e7035ade9bc3ca34b985de Mon Sep 17 00:00:00 2001 From: Raul Victor Trombin Date: Wed, 11 Dec 2024 17:55:27 -0300 Subject: [PATCH] add cors rust server --- Cargo.toml | 1 + src/server/manager.rs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 99bdee12..fd1c57fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ thiserror = "1.0.63" shellexpand = "3.1" tauri = { version = "1.7.2", optional = true, features = ["shell-open"] } +actix-cors = "0.7.0" [build-dependencies] diff --git a/src/server/manager.rs b/src/server/manager.rs index 6b1bed93..963a8900 100644 --- a/src/server/manager.rs +++ b/src/server/manager.rs @@ -1,7 +1,8 @@ use crate::device::manager::ManagerActorHandler; use super::protocols; -use actix_web::{middleware, web::Data, App, HttpServer}; +use actix_cors::Cors; +use actix_web::{http, middleware, web::Data, App, HttpServer}; use tracing::info; use paperclip::actix::{ @@ -18,11 +19,14 @@ pub async fn run(server_address: &str, handler: ManagerActorHandler) -> std::io: info!("ServerManager: Service starting"); let server = HttpServer::new(move || { + let cors = Cors::permissive(); + let v1 = add_v1_paths(web::scope("/v1")); let default = add_v1_paths(web::scope("")); App::new() .app_data(Data::new(handler.clone())) + .wrap(cors) .wrap(middleware::Logger::default()) .wrap_api() .with_json_spec_at("/api/spec")