From ea59bd03f5256fa33c100abe6dd23350489aeaad Mon Sep 17 00:00:00 2001 From: mrjvs Date: Sat, 6 Jan 2024 19:30:11 +0100 Subject: [PATCH] Fix url bug --- src/providers.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/providers.ts b/src/providers.ts index b8b2725..dcd44ea 100644 --- a/src/providers.ts +++ b/src/providers.ts @@ -9,9 +9,21 @@ export function getProviders(context: Context) { const specialDomains = specialDomainsEnv.split(",").map(v=>v.trim()).filter(v=>v.length>0); const fetcher: RealFetcher = (u,ops) => { - const url = new URL(u); - if (specialDomains.includes(url.hostname) && !!proxyUrl) - return makeSimpleProxyFetcher(proxyUrl, fetch)(u, ops); + let url: URL | null = null; + try { + if (ops.baseUrl) { + const baseUrl = ops.baseUrl.endsWith("/") ? ops.baseUrl.slice(0, -1) : ops.baseUrl; + const path = u.startsWith("/") ? u : u.slice(0, -1); + url = new URL(baseUrl + path); + } else { + url = new URL(u); + } + if (specialDomains.includes(url.hostname) && !!proxyUrl) + return makeSimpleProxyFetcher(proxyUrl, fetch)(u, ops); + } catch { + return standardFetcher(u, ops); + } + return standardFetcher(u, ops); };