From 5462b97c26cd7b8426919aee5bb6d5761299d15f Mon Sep 17 00:00:00 2001 From: BlockListed <44610569+BlockListed@users.noreply.github.com> Date: Sat, 9 Sep 2023 11:16:24 +0200 Subject: [PATCH] make cors work with multi-domains --- src/util.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/util.rs b/src/util.rs index 2f04fe34..b00fb205 100644 --- a/src/util.rs +++ b/src/util.rs @@ -17,7 +17,7 @@ use tokio::{ time::{sleep, Duration}, }; -use crate::CONFIG; +use crate::{CONFIG, config::extract_url_host}; pub struct AppHeaders(); @@ -129,9 +129,19 @@ impl Cors { // If a match exists, return it. Otherwise, return None. fn get_allowed_origin(headers: &HeaderMap<'_>) -> Option { let origin = Cors::get_header(headers, "Origin"); - let domain_origin = CONFIG.domain_origin(); + + let domain_origin_opt = CONFIG.domain_origin(&extract_url_host(&origin)); let safari_extension_origin = "file://"; - if origin == domain_origin || origin == safari_extension_origin { + + let found_origin = { + if let Some(domain_origin) = domain_origin_opt { + origin == domain_origin + } else { + false + } + }; + + if found_origin || origin == safari_extension_origin { Some(origin) } else { None