| 62 | } |
| 63 | |
| 64 | async function convertToStandardRequest(nextReq: NextApiRequest): Promise<Request> { |
| 65 | const { headers: nextHeaders, method } = nextReq; |
| 66 | |
| 67 | const headers = new Headers(); |
| 68 | |
| 69 | Object.entries(nextHeaders).forEach(([key, value]) => { |
| 70 | headers.set(key, value as string); |
| 71 | }); |
| 72 | |
| 73 | // Create a new Request object (hardcode the url because it doesn't really matter what it is) |
| 74 | const webReq = new Request("https://next.js/api/trigger", { |
| 75 | headers, |
| 76 | method, |
| 77 | // @ts-ignore |
| 78 | body: nextReq, |
| 79 | duplex: "half", |
| 80 | }); |
| 81 | |
| 82 | return webReq; |
| 83 | } |