| 23 | |
| 24 | function createWorkerFetch(client: RpcClient): typeof fetch { |
| 25 | const fn = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => { |
| 26 | const request = new Request(input, init) |
| 27 | const body = request.body ? await request.text() : undefined |
| 28 | const result = await client.call("fetch", { |
| 29 | url: request.url, |
| 30 | method: request.method, |
| 31 | headers: Object.fromEntries(request.headers.entries()), |
| 32 | body, |
| 33 | }) |
| 34 | return new Response(result.body, { |
| 35 | status: result.status, |
| 36 | headers: result.headers, |
| 37 | }) |
| 38 | } |
| 39 | return fn as typeof fetch |
| 40 | } |
| 41 | |