(path: string, body?: string | Record<string, any>)
| 44 | } |
| 45 | |
| 46 | export const post = (path: string, body?: string | Record<string, any>) => |
| 47 | typeof body === 'string' |
| 48 | ? new Request(`http://localhost${path}`, { |
| 49 | method: 'POST', |
| 50 | headers: { |
| 51 | 'Content-Type': 'text/plain', |
| 52 | 'Content-Length': String(Buffer.byteLength(body)) |
| 53 | }, |
| 54 | body |
| 55 | }) |
| 56 | : new Request(`http://localhost${path}`, { |
| 57 | method: 'POST', |
| 58 | headers: body |
| 59 | ? { |
| 60 | 'Content-Type': 'application/json', |
| 61 | 'Content-Length': String( |
| 62 | Buffer.byteLength(JSON.stringify(body)) |
| 63 | ) |
| 64 | } |
| 65 | : {}, |
| 66 | body: body ? JSON.stringify(body) : body |
| 67 | }) |
| 68 | |
| 69 | export const delay = (delay: number) => |
| 70 | new Promise((resolve) => setTimeout(resolve, delay)) |
no outgoing calls