Skip to content

Commit b8439aa

Browse files
committed
server: add axios post shim
1 parent 77d0c33 commit b8439aa

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Diff for: server/src/fetch-helpers.ts

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ export async function fetchJSON(url: string, init?: RequestInit) {
66
return await (await fetch(url, init)).json();
77
}
88

9+
export async function fetchPostJSON(url: string, body: any, init?: RequestInit) {
10+
init ||= {};
11+
init.body = JSON.stringify(body);
12+
init.method = 'POST';
13+
init.headers = {
14+
...init.headers,
15+
'Content-Type': 'application/json',
16+
};
17+
return await (await fetch(url, init)).json();
18+
}
19+
920
export async function fetchBuffer(url: string, init?: RequestInit) {
1021
return Buffer.from(await (await fetch(url, init)).arrayBuffer());
1122
}

0 commit comments

Comments
 (0)