mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 17:13:25 +00:00
remove node-fetch as runtime dependency
This commit is contained in:
22
src/fetchers/fetch.ts
Normal file
22
src/fetchers/fetch.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* This file is a very relaxed definition of the fetch api
|
||||
* Only containing what we need for it to function.
|
||||
*/
|
||||
|
||||
export type FetchOps = {
|
||||
headers: Record<string, string>;
|
||||
method: string;
|
||||
body: any;
|
||||
};
|
||||
|
||||
export type FetchHeaders = {
|
||||
get(key: string): string | undefined;
|
||||
};
|
||||
|
||||
export type FetchReply = {
|
||||
text(): Promise<string>;
|
||||
json(): Promise<any>;
|
||||
headers: FetchHeaders;
|
||||
};
|
||||
|
||||
export type FetchType = (url: string, ops?: FetchOps) => Promise<FetchReply>;
|
@@ -1,6 +1,5 @@
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
import { makeFullUrl } from '@/fetchers/common';
|
||||
import { FetchType } from '@/fetchers/fetch';
|
||||
import { makeStandardFetcher } from '@/fetchers/standardFetch';
|
||||
import { Fetcher } from '@/fetchers/types';
|
||||
|
||||
@@ -10,7 +9,7 @@ const headerMap: Record<string, string> = {
|
||||
origin: 'X-Origin',
|
||||
};
|
||||
|
||||
export function makeSimpleProxyFetcher(proxyUrl: string, f: typeof fetch): Fetcher {
|
||||
export function makeSimpleProxyFetcher(proxyUrl: string, f: FetchType): Fetcher {
|
||||
const fetcher = makeStandardFetcher(f);
|
||||
const proxiedFetch: Fetcher = async (url, ops) => {
|
||||
const fullUrl = makeFullUrl(url, ops);
|
||||
|
@@ -1,10 +1,9 @@
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
import { serializeBody } from '@/fetchers/body';
|
||||
import { makeFullUrl } from '@/fetchers/common';
|
||||
import { FetchType } from '@/fetchers/fetch';
|
||||
import { Fetcher } from '@/fetchers/types';
|
||||
|
||||
export function makeStandardFetcher(f: typeof fetch): Fetcher {
|
||||
export function makeStandardFetcher(f: FetchType): Fetcher {
|
||||
const normalFetch: Fetcher = async (url, ops) => {
|
||||
const fullUrl = makeFullUrl(url, ops);
|
||||
const seralizedBody = serializeBody(ops.body);
|
||||
|
Reference in New Issue
Block a user