Add overrides for proxying specific domains

This commit is contained in:
mrjvs
2024-01-06 17:34:40 +01:00
parent cc0dc6af64
commit 97fe076afa
2 changed files with 26 additions and 14 deletions

21
src/providers.ts Normal file
View File

@@ -0,0 +1,21 @@
import { makeProviders, makeSimpleProxyFetcher, makeStandardFetcher, targets, Fetcher as RealFetcher } from "@movie-web/providers";
import { Context, Env } from "hono";
const specialDomains = ["showbox.shegu.net", "mbpapi.shegu.net"]
const standardFetcher = makeStandardFetcher(fetch);
export function getProviders(context: Context<Env>) {
const proxyUrl = (context.env?.PROXY_URL as string | undefined) ?? '';
const fetcher: RealFetcher = (u,ops) => {
const url = new URL(u);
if (specialDomains.includes(url.hostname) && !!proxyUrl)
return makeSimpleProxyFetcher(proxyUrl, fetch)(u, ops);
return standardFetcher(u, ops);
};
return makeProviders({
fetcher,
target: targets.BROWSER,
});
}