@trigger.dev/nextjs and @trigger.dev/sdk: Set duplex "half" when creating fetch based Request objects when they have a body

This commit is contained in:
Eric Allam
2023-07-12 21:40:13 +01:00
parent 953354f367
commit d6310a79fa
3 changed files with 27 additions and 6 deletions
+6
View File
@@ -0,0 +1,6 @@
---
"@trigger.dev/sdk": patch
"@trigger.dev/nextjs": patch
---
Set duplex "half" when creating fetch based Request objects when they have a body
+1
View File
@@ -66,6 +66,7 @@ async function convertToStandardRequest(
method,
// @ts-ignore
body: nextReq,
duplex: "half",
});
return webReq;
+20 -6
View File
@@ -359,14 +359,28 @@ export class TriggerClient {
};
}
const sourceRequest = new Request(headers.data["x-ts-http-url"], {
const sourceRequestNeedsBody =
headers.data["x-ts-http-method"] !== "GET";
const sourceRequestInit: RequestInit = {
method: headers.data["x-ts-http-method"],
headers: headers.data["x-ts-http-headers"],
body:
headers.data["x-ts-http-method"] !== "GET"
? request.body
: undefined,
});
body: sourceRequestNeedsBody ? request.body : undefined,
};
if (sourceRequestNeedsBody) {
try {
// @ts-ignore
sourceRequestInit.duplex = "half";
} catch (error) {
// ignore
}
}
const sourceRequest = new Request(
headers.data["x-ts-http-url"],
sourceRequestInit
);
const key = headers.data["x-ts-key"];
const dynamicId = headers.data["x-ts-dynamic-id"];