| 15 | }; |
| 16 | |
| 17 | const requestJson = async <T>(origin: string, path: string, init: RequestInit = {}): Promise<T> => { |
| 18 | const response = await fetch(new URL(path, origin), { |
| 19 | ...init, |
| 20 | headers: { |
| 21 | authorization: `Bearer ${AUTH_TOKEN}`, |
| 22 | ...(init.body === undefined ? {} : { "content-type": "application/json" }), |
| 23 | ...init.headers, |
| 24 | }, |
| 25 | }); |
| 26 | const text = await response.text(); |
| 27 | if (!response.ok) fail(`${init.method ?? "GET"} ${path} returned ${response.status}: ${text}`); |
| 28 | return (text.length > 0 ? JSON.parse(text) : null) as T; |
| 29 | }; |
| 30 | |
| 31 | const waitForReadyPort = async (proc: Subprocess<"ignore", "pipe", "pipe">): Promise<number> => |
| 32 | new Promise((resolveReady, rejectReady) => { |