Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
updates conditional within getPayload()
Browse files Browse the repository at this point in the history
  • Loading branch information
didley committed May 5, 2024
1 parent 0ca725c commit 6a8cd28
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/middleware/node/get-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ import AggregateError from "aggregate-error";
type IncomingMessage = any;

export function getPayload(request: IncomingMessage): Promise<string> {
if (request.body) {
if (
typeof request.body === "object" &&
"rawBody" in request &&
request.rawBody instanceof Buffer
) {
// The body is already an Object and rawBody is a Buffer (e.g. GCF)
return Promise.resolve(request.rawBody.toString("utf8"));
} else {
// The body is a String (e.g. Lambda)
return Promise.resolve(request.body);
}
if (
typeof request.body === "object" &&
"rawBody" in request &&
request.rawBody instanceof Buffer
) {
// The body is already an Object and rawBody is a Buffer (e.g. GCF)
return Promise.resolve(request.rawBody.toString("utf8"));
} else if (typeof request.body === "string") {
// The body is a String (e.g. Lambda)
return Promise.resolve(request.body);
}

// We need to load the payload from the request (normal case of Node.js server)
Expand Down

0 comments on commit 6a8cd28

Please sign in to comment.