mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 18:13:25 +00:00
remove node-fetch as runtime dependency
This commit is contained in:
@@ -61,12 +61,12 @@
|
|||||||
"vite": "^4.0.0",
|
"vite": "^4.0.0",
|
||||||
"vite-plugin-dts": "^3.5.3",
|
"vite-plugin-dts": "^3.5.3",
|
||||||
"vite-plugin-eslint": "^1.8.1",
|
"vite-plugin-eslint": "^1.8.1",
|
||||||
"vitest": "^0.32.2"
|
"vitest": "^0.32.2",
|
||||||
|
"node-fetch": "^3.3.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cheerio": "^1.0.0-rc.12",
|
"cheerio": "^1.0.0-rc.12",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0"
|
||||||
"node-fetch": "^3.3.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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 { makeFullUrl } from '@/fetchers/common';
|
||||||
|
import { FetchType } from '@/fetchers/fetch';
|
||||||
import { makeStandardFetcher } from '@/fetchers/standardFetch';
|
import { makeStandardFetcher } from '@/fetchers/standardFetch';
|
||||||
import { Fetcher } from '@/fetchers/types';
|
import { Fetcher } from '@/fetchers/types';
|
||||||
|
|
||||||
@@ -10,7 +9,7 @@ const headerMap: Record<string, string> = {
|
|||||||
origin: 'X-Origin',
|
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 fetcher = makeStandardFetcher(f);
|
||||||
const proxiedFetch: Fetcher = async (url, ops) => {
|
const proxiedFetch: Fetcher = async (url, ops) => {
|
||||||
const fullUrl = makeFullUrl(url, ops);
|
const fullUrl = makeFullUrl(url, ops);
|
||||||
|
@@ -1,10 +1,9 @@
|
|||||||
import fetch from 'node-fetch';
|
|
||||||
|
|
||||||
import { serializeBody } from '@/fetchers/body';
|
import { serializeBody } from '@/fetchers/body';
|
||||||
import { makeFullUrl } from '@/fetchers/common';
|
import { makeFullUrl } from '@/fetchers/common';
|
||||||
|
import { FetchType } from '@/fetchers/fetch';
|
||||||
import { Fetcher } from '@/fetchers/types';
|
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 normalFetch: Fetcher = async (url, ops) => {
|
||||||
const fullUrl = makeFullUrl(url, ops);
|
const fullUrl = makeFullUrl(url, ops);
|
||||||
const seralizedBody = serializeBody(ops.body);
|
const seralizedBody = serializeBody(ops.body);
|
||||||
|
Reference in New Issue
Block a user