|
36 | 36 | // secret. The wrapper imports the handler from exit_node.ts directly, |
37 | 37 | // so changing the constant in exit_node.ts is all you need. |
38 | 38 |
|
39 | | -import handler from "./exit_node.ts"; |
| 39 | +import exitNode from "./exit_node.ts"; |
| 40 | + |
| 41 | +const handler = |
| 42 | + typeof exitNode === "function" ? exitNode : exitNode.fetch.bind(exitNode); |
| 43 | + |
| 44 | +function concatChunks(chunks: Uint8Array[]): Blob | undefined { |
| 45 | + if (!chunks.length) return undefined; |
| 46 | + const len = chunks.reduce((sum, chunk) => sum + chunk.length, 0); |
| 47 | + const out = new Uint8Array(len); |
| 48 | + let offset = 0; |
| 49 | + for (const chunk of chunks) { |
| 50 | + out.set(chunk, offset); |
| 51 | + offset += chunk.length; |
| 52 | + } |
| 53 | + return new Blob([out.buffer as ArrayBuffer]); |
| 54 | +} |
40 | 55 |
|
41 | 56 | // Deno (preferred) |
42 | 57 | if (typeof (globalThis as any).Deno !== "undefined") { |
@@ -94,7 +109,7 @@ else if (typeof (globalThis as any).process !== "undefined") { |
94 | 109 | // Build a web-standard Request from Node's IncomingMessage. |
95 | 110 | const chunks: Uint8Array[] = []; |
96 | 111 | for await (const c of req) chunks.push(c as Uint8Array); |
97 | | - const body = chunks.length ? Buffer.concat(chunks) : undefined; |
| 112 | + const body = concatChunks(chunks); |
98 | 113 |
|
99 | 114 | const url = `http://${req.headers.host ?? hostname}${req.url ?? "/"}`; |
100 | 115 | const webReq = new Request(url, { |
|
0 commit comments