Skip to content

Commit

Permalink
handle Netlify form data handling as encoded URL (#1148)
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Nov 9, 2023
1 parent beae966 commit 2152cb5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/plugin-adapter-netlify/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ function generateOutputFormat(id) {
if (['GET', 'HEAD'].includes(httpMethod.toUpperCase())) {
format = null
} else if (contentType.includes('application/x-www-form-urlencoded')) {
const searchParams = new URLSearchParams(body);
const formData = new FormData();
for (const key of Object.keys(body)) {
formData.append(key, body[key]);
for (const key of searchParams.keys()) {
const value = searchParams.get(key);
formData.append(key, value);
}
// when using FormData, let Request set the correct headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe('Build Greenwood With: ', function() {
const { handler } = await import(new URL(`./${name}/${name}.js`, netlifyFunctionsOutputUrl));
const response = await handler({
rawUrl: 'http://localhost:8080/api/submit-form-data',
body: { name: param },
body: `name=${param}`,
httpMethod: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded'
Expand Down

0 comments on commit 2152cb5

Please sign in to comment.