diff --git a/Makefile b/Makefile index ebed1ac..34b7dc8 100644 --- a/Makefile +++ b/Makefile @@ -17,14 +17,17 @@ webui-build: webui-deps @PHONY: devserver devserver: - echo -n '' > /tmp/rqbit-log && cargo run -- \ + echo -n '' > /tmp/rqbit-log && CORS_ALLOW_REGEXP=".*" \ + cargo run -- \ --log-file /tmp/rqbit-log \ --log-file-rust-log=debug,librqbit=trace \ + --http-api-listen-addr 0.0.0.0:3030 \ server start /tmp/scratch/ @PHONY: devserver devserver-postgres: - echo -n '' > /tmp/rqbit-log && cargo run -- \ + echo -n '' > /tmp/rqbit-log && CORS_ALLOW_REGEXP=".*" \ + cargo run -- \ --log-file /tmp/rqbit-log \ --log-file-rust-log=debug,librqbit=trace \ server start --fastresume --persistence-config postgres:///rqbit /tmp/scratch/ diff --git a/crates/librqbit/src/http_api.rs b/crates/librqbit/src/http_api.rs index fd672d0..7e17445 100644 --- a/crates/librqbit/src/http_api.rs +++ b/crates/librqbit/src/http_api.rs @@ -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()) }; diff --git a/crates/librqbit/webui/src/components/Footer.tsx b/crates/librqbit/webui/src/components/Footer.tsx index b248071..21c7dac 100644 --- a/crates/librqbit/webui/src/components/Footer.tsx +++ b/crates/librqbit/webui/src/components/Footer.tsx @@ -5,13 +5,13 @@ import { useStatsStore } from "../stores/statsStore"; export const Footer: React.FC<{}> = () => { let stats = useStatsStore((stats) => stats.stats); return ( -