Files
providers/src/fetchers/standardFetch.ts
2023-09-06 15:09:52 +02:00

25 lines
587 B
TypeScript

import fetch from 'node-fetch';
import { serializeBody } from '@/fetchers/body';
import { makeFullUrl } from '@/fetchers/common';
import { Fetcher } from '@/fetchers/types';
export function makeStandardFetcher(f: typeof fetch): Fetcher {
const normalFetch: Fetcher = (url, ops) => {
const fullUrl = makeFullUrl(url, ops);
const seralizedBody = serializeBody(ops.body);
return f(fullUrl, {
method: ops.method,
headers: {
...seralizedBody.headers,
...ops.headers,
},
body: seralizedBody.body,
});
};
return normalFetch;
}