Skip to content

Commit

Permalink
[fix] adapter-netlify: handle undefined body
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Oct 25, 2021
1 parent 73658c5 commit c538704
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-eels-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-netlify': patch
---

[fix] adapter-netlify: handle undefined body
14 changes: 7 additions & 7 deletions packages/adapter-netlify/files/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ export async function handler(event) {
...split_headers(rendered.headers)
};

if (typeof rendered.body === 'string') {
if (rendered.body instanceof Uint8Array) {
// Function responses should always be strings, and responses with binary
// content should be base64 encoded and set isBase64Encoded to true.
// https://github.com/netlify/functions/blob/main/src/function/response.d.ts
return {
...partial_response,
body: rendered.body
isBase64Encoded: true,
body: Buffer.from(rendered.body).toString('base64')
};
}

// Function responses should always be strings, and responses with binary
// content should be base64 encoded and set isBase64Encoded to true.
// https://github.com/netlify/functions/blob/main/src/function/response.d.ts
return {
...partial_response,
isBase64Encoded: true,
body: Buffer.from(rendered.body).toString('base64')
body: rendered.body
};
}

Expand Down

0 comments on commit c538704

Please sign in to comment.