Merge pull request #301 from ikatson/api-base-2
[Feature] Can put rqbit Web UI behind proxy server
This commit is contained in:
commit
6cb4289917
1 changed files with 13 additions and 8 deletions
|
|
@ -10,21 +10,26 @@ import {
|
||||||
|
|
||||||
// Define API URL and base path
|
// Define API URL and base path
|
||||||
const apiUrl = (() => {
|
const apiUrl = (() => {
|
||||||
if (window.origin === "null" || window.origin === "http://localhost:3031") {
|
if (window.origin === "null") {
|
||||||
return "http://localhost:3030";
|
return "http://localhost:3030";
|
||||||
}
|
}
|
||||||
let port = /http.*:\/\/.*:(\d+)/.exec(window.origin)?.[1];
|
const url = new URL(window.location.href);
|
||||||
if (port == "3031") {
|
|
||||||
return window.origin.replace("3031", "3030");
|
// 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 (
|
const makeRequest = async (
|
||||||
method: string,
|
method: string,
|
||||||
path: string,
|
path: string,
|
||||||
data?: any,
|
data?: any,
|
||||||
isJson?: boolean,
|
isJson?: boolean
|
||||||
): Promise<any> => {
|
): Promise<any> => {
|
||||||
console.log(method, path);
|
console.log(method, path);
|
||||||
const url = apiUrl + path;
|
const url = apiUrl + path;
|
||||||
|
|
@ -127,7 +132,7 @@ export const API: RqbitAPI & { getVersion: () => Promise<string> } = {
|
||||||
{
|
{
|
||||||
only_files: files,
|
only_files: files,
|
||||||
},
|
},
|
||||||
true,
|
true
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -153,7 +158,7 @@ export const API: RqbitAPI & { getVersion: () => Promise<string> } = {
|
||||||
getTorrentStreamUrl: (
|
getTorrentStreamUrl: (
|
||||||
index: number,
|
index: number,
|
||||||
file_id: number,
|
file_id: number,
|
||||||
filename?: string | null,
|
filename?: string | null
|
||||||
) => {
|
) => {
|
||||||
let url = apiUrl + `/torrents/${index}/stream/${file_id}`;
|
let url = apiUrl + `/torrents/${index}/stream/${file_id}`;
|
||||||
if (!!filename) {
|
if (!!filename) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue