Small tweaks (cors etc)

This commit is contained in:
Igor Katson 2024-08-21 22:27:58 +01:00
parent 1a1d07e5cb
commit 0c9a5093d0
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
5 changed files with 28 additions and 10 deletions

View file

@ -543,9 +543,17 @@ impl HttpApi {
b"tauri://localhost",
];
let allow_regex = std::env::var("CORS_ALLOW_REGEXP")
.ok()
.and_then(|value| regex::bytes::Regex::new(&value).ok());
tower_http::cors::CorsLayer::default()
.allow_origin(AllowOrigin::predicate(|v, _| {
.allow_origin(AllowOrigin::predicate(move |v, _| {
ALLOWED_ORIGINS.contains(&v.as_bytes())
|| allow_regex
.as_ref()
.map(move |r| r.is_match(v.as_bytes()))
.unwrap_or(false)
}))
.allow_headers(AllowHeaders::any())
};