mirror of
https://github.com/movie-web/providers-api.git
synced 2025-09-13 14:23:29 +00:00
Add overrides for proxying specific domains
This commit is contained in:
21
src/providers.ts
Normal file
21
src/providers.ts
Normal 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,
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user