| 3 | const timeout = 15000; |
| 4 | |
| 5 | async function request(url, options = {}) { |
| 6 | const { json, form, body, headers = {}, ...rest } = options; |
| 7 | |
| 8 | const finalHeaders = { ...headers }; |
| 9 | let finalBody = body; |
| 10 | |
| 11 | if (json) { |
| 12 | finalHeaders['content-type'] = 'application/json'; |
| 13 | finalBody = JSON.stringify(json); |
| 14 | } else if (form) { |
| 15 | finalBody = form; |
| 16 | delete finalHeaders['content-type']; |
| 17 | } |
| 18 | |
| 19 | return undiciRequest(url, { |
| 20 | headers: finalHeaders, |
| 21 | body: finalBody, |
| 22 | ...rest, |
| 23 | }); |
| 24 | } |
| 25 | |
| 26 | function post(url, options = {}) { |
| 27 | return request(url, { ...options, method: 'POST' }); |