From 970922eb66b20f34766e9563c0e70899de7c5dd4 Mon Sep 17 00:00:00 2001 From: Kirill Gadjello Date: Fri, 28 Jun 2024 07:13:03 -0300 Subject: [PATCH] feat: Add optional CORS allow any option value in http server cli (#260) --- router/src/http/server.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/router/src/http/server.rs b/router/src/http/server.rs index 17baada6..35f5c1fb 100644 --- a/router/src/http/server.rs +++ b/router/src/http/server.rs @@ -1534,11 +1534,15 @@ pub async fn run( // map to go inside the option and then map to parse from String to HeaderValue // Finally, convert to AllowOrigin let allow_origin: Option = cors_allow_origin.map(|cors_allow_origin| { - AllowOrigin::list( - cors_allow_origin - .into_iter() - .map(|origin| origin.parse::().unwrap()), - ) + if cors_allow_origin.iter().any(|origin| origin == "*") { + AllowOrigin::any() + } else { + AllowOrigin::list( + cors_allow_origin + .into_iter() + .map(|origin| origin.parse::().unwrap()), + ) + } }); let prom_handle = prom_builder