| 18 | } |
| 19 | |
| 20 | async function convertToStandardRequest(req: Request): Promise<Request> { |
| 21 | // Prepare the request to be a fetch-compatible Request object: |
| 22 | const requestHeaders = req.headers; |
| 23 | const requestMethod = req.method; |
| 24 | const responseHeaders = Object.create(null); |
| 25 | |
| 26 | for (const [headerName, headerValue] of requestHeaders.entries()) { |
| 27 | responseHeaders[headerName] = headerValue; |
| 28 | } |
| 29 | |
| 30 | // Create a new Request object to be passed to the TriggerClient |
| 31 | // where we pass the clone the incoming request metadata such as |
| 32 | // headers, method, body. |
| 33 | const request = new Request("https://svelte/api/trigger", { |
| 34 | headers: responseHeaders, |
| 35 | method: requestMethod, |
| 36 | // @ts-ignore |
| 37 | body: req.body ? req.body : req, |
| 38 | duplex: "half", |
| 39 | }); |
| 40 | |
| 41 | return request; |
| 42 | } |