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 ( -
+
- ↓ {stats.download_speed.human_readable} (total{" "} + ↓ {stats.download_speed.human_readable} ( {formatBytes(stats.fetched_bytes)})
- ↑ {stats.upload_speed.human_readable} (total{" "} + ↑ {stats.upload_speed.human_readable} ( {formatBytes(stats.uploaded_bytes)})
up {formatSecondsToTime(stats.uptime_seconds)}
diff --git a/crates/librqbit/webui/src/http-api.ts b/crates/librqbit/webui/src/http-api.ts index 3bf66d8..5db88c2 100644 --- a/crates/librqbit/webui/src/http-api.ts +++ b/crates/librqbit/webui/src/http-api.ts @@ -9,10 +9,16 @@ import { } from "./api-types"; // Define API URL and base path -const apiUrl = - window.origin === "null" || window.origin === "http://localhost:3031" - ? "http://localhost:3030" - : ""; +const apiUrl = (() => { + if (window.origin === "null" || window.origin === "http://localhost:3031") { + return "http://localhost:3030" + } + let port = /http.*:\/\/.*:(\d+)/.exec(window.origin)?.[1]; + if (port == "3031") { + return window.origin.replace("3031", "3030"); + } + return ""; +})(); const makeRequest = async ( method: string, diff --git a/crates/librqbit/webui/vite.config.ts b/crates/librqbit/webui/vite.config.ts index f097378..1025c64 100644 --- a/crates/librqbit/webui/vite.config.ts +++ b/crates/librqbit/webui/vite.config.ts @@ -6,6 +6,7 @@ import svgr from "vite-plugin-svgr"; export default defineConfig({ plugins: [react(), svgr()], server: { + host: true, port: 3031, }, build: {