fetcher seralization

This commit is contained in:
mrjvs
2023-09-06 15:09:52 +02:00
parent ec3efbd344
commit 637b3b635a
4 changed files with 33 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
import fetch from 'node-fetch';
import { serializeBody } from '@/fetchers/body';
import { makeFullUrl } from '@/fetchers/common';
import { Fetcher } from '@/fetchers/types';
@@ -7,9 +8,15 @@ 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,
body: JSON.stringify(ops.body), // TODO content type headers + proper serialization
headers: {
...seralizedBody.headers,
...ops.headers,
},
body: seralizedBody.body,
});
};