proxied fetch support

This commit is contained in:
josc146
2024-03-26 21:23:09 +08:00
parent c2799c9494
commit 08bc342fd6
6 changed files with 96 additions and 0 deletions

View File

@@ -310,6 +310,24 @@ export function bytesToReadable(size: number) {
else return bytesToGb(size) + ' GB';
}
export async function getReqUrl(port: number, path: string, isCore: boolean = false): Promise<{
url: string,
headers: { [key: string]: string }
}> {
const realUrl = getServerRoot(port, isCore) + path;
if (commonStore.platform === 'web')
return {
url: realUrl,
headers: {}
};
if (!commonStore.proxyPort)
await GetProxyPort().then(p => commonStore.setProxyPort(p));
return {
url: `http://127.0.0.1:${commonStore.proxyPort}`,
headers: { 'Real-Target': realUrl }
};
}
export function getServerRoot(defaultLocalPort: number, isCore: boolean = false) {
const coreCustomApiUrl = commonStore.settings.coreApiUrl.trim().replace(/\/$/, '');
if (isCore && coreCustomApiUrl)