Skip to content

Commit

Permalink
Merge pull request #301 from ikatson/api-base-2
Browse files Browse the repository at this point in the history
[Feature] Can put rqbit Web UI behind proxy server
  • Loading branch information
ikatson authored Jan 13, 2025
2 parents bbae577 + 0245861 commit 6cb4289
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions crates/librqbit/webui/src/http-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ import {

// Define API URL and base path
const apiUrl = (() => {
if (window.origin === "null" || window.origin === "http://localhost:3031") {
if (window.origin === "null") {
return "http://localhost:3030";
}
let port = /http.*:\/\/.*:(\d+)/.exec(window.origin)?.[1];
if (port == "3031") {
return window.origin.replace("3031", "3030");
const url = new URL(window.location.href);

// assume Vite devserver
if (url.port == "3031") {
return `${url.protocol}//${url.hostname}:3030`;
}
return "";

// Remove "/web" or "/web/" from the end and also ending slash.
const path = /(.*?)\/?(\/web\/?)?$/.exec(url.pathname)![1] ?? "";
return path;
})();

const makeRequest = async (
method: string,
path: string,
data?: any,
isJson?: boolean,
isJson?: boolean
): Promise<any> => {
console.log(method, path);
const url = apiUrl + path;
Expand Down Expand Up @@ -127,7 +132,7 @@ export const API: RqbitAPI & { getVersion: () => Promise<string> } = {
{
only_files: files,
},
true,
true
);
},

Expand All @@ -153,7 +158,7 @@ export const API: RqbitAPI & { getVersion: () => Promise<string> } = {
getTorrentStreamUrl: (
index: number,
file_id: number,
filename?: string | null,
filename?: string | null
) => {
let url = apiUrl + `/torrents/${index}/stream/${file_id}`;
if (!!filename) {
Expand Down

0 comments on commit 6cb4289

Please sign in to comment.