Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] adapter-netlify: handle undefined body #2682

Merged
merged 1 commit into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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