Small tweaks (cors etc)
This commit is contained in:
parent
1a1d07e5cb
commit
0c9a5093d0
5 changed files with 28 additions and 10 deletions
7
Makefile
7
Makefile
|
|
@ -17,14 +17,17 @@ webui-build: webui-deps
|
||||||
|
|
||||||
@PHONY: devserver
|
@PHONY: devserver
|
||||||
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 /tmp/rqbit-log \
|
||||||
--log-file-rust-log=debug,librqbit=trace \
|
--log-file-rust-log=debug,librqbit=trace \
|
||||||
|
--http-api-listen-addr 0.0.0.0:3030 \
|
||||||
server start /tmp/scratch/
|
server start /tmp/scratch/
|
||||||
|
|
||||||
@PHONY: devserver
|
@PHONY: devserver
|
||||||
devserver-postgres:
|
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 /tmp/rqbit-log \
|
||||||
--log-file-rust-log=debug,librqbit=trace \
|
--log-file-rust-log=debug,librqbit=trace \
|
||||||
server start --fastresume --persistence-config postgres:///rqbit /tmp/scratch/
|
server start --fastresume --persistence-config postgres:///rqbit /tmp/scratch/
|
||||||
|
|
|
||||||
|
|
@ -543,9 +543,17 @@ impl HttpApi {
|
||||||
b"tauri://localhost",
|
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()
|
tower_http::cors::CorsLayer::default()
|
||||||
.allow_origin(AllowOrigin::predicate(|v, _| {
|
.allow_origin(AllowOrigin::predicate(move |v, _| {
|
||||||
ALLOWED_ORIGINS.contains(&v.as_bytes())
|
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())
|
.allow_headers(AllowHeaders::any())
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ import { useStatsStore } from "../stores/statsStore";
|
||||||
export const Footer: React.FC<{}> = () => {
|
export const Footer: React.FC<{}> = () => {
|
||||||
let stats = useStatsStore((stats) => stats.stats);
|
let stats = useStatsStore((stats) => stats.stats);
|
||||||
return (
|
return (
|
||||||
<div className="sticky bottom-0 bg-white/10 dark:text-gray-200 backdrop-blur text-nowrap text-xs font-medium text-gray-500 flex p-1 gap-x-3 justify-center">
|
<div className="sticky bottom-0 bg-white/10 dark:text-gray-200 backdrop-blur text-nowrap text-xs font-medium text-gray-500 flex p-2 gap-x-5 justify-evenly flex-wrap">
|
||||||
<div>
|
<div>
|
||||||
↓ {stats.download_speed.human_readable} (total{" "}
|
↓ {stats.download_speed.human_readable} (
|
||||||
{formatBytes(stats.fetched_bytes)})
|
{formatBytes(stats.fetched_bytes)})
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
↑ {stats.upload_speed.human_readable} (total{" "}
|
↑ {stats.upload_speed.human_readable} (
|
||||||
{formatBytes(stats.uploaded_bytes)})
|
{formatBytes(stats.uploaded_bytes)})
|
||||||
</div>
|
</div>
|
||||||
<div>up {formatSecondsToTime(stats.uptime_seconds)}</div>
|
<div>up {formatSecondsToTime(stats.uptime_seconds)}</div>
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,16 @@ import {
|
||||||
} from "./api-types";
|
} from "./api-types";
|
||||||
|
|
||||||
// Define API URL and base path
|
// Define API URL and base path
|
||||||
const apiUrl =
|
const apiUrl = (() => {
|
||||||
window.origin === "null" || window.origin === "http://localhost:3031"
|
if (window.origin === "null" || window.origin === "http://localhost:3031") {
|
||||||
? "http://localhost:3030"
|
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 (
|
const makeRequest = async (
|
||||||
method: string,
|
method: string,
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import svgr from "vite-plugin-svgr";
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react(), svgr()],
|
plugins: [react(), svgr()],
|
||||||
server: {
|
server: {
|
||||||
|
host: true,
|
||||||
port: 3031,
|
port: 3031,
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue