Skip to content

Commit

Permalink
fix: work around SWA issue with empty form bodies (#179)
Browse files Browse the repository at this point in the history
* fix: work around SWA issue with empty form bodies

* chore: more debug logs
  • Loading branch information
geoffrich authored Jul 13, 2024
1 parent 9b4d834 commit d14aae1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions files/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export async function index(context) {
const request = toRequest(context);

if (debug) {
context.log(
'Starting request',
context?.req?.method,
context?.req?.headers?.['x-ms-original-url']
);
context.log(`Original request: ${JSON.stringify(context)}`);
context.log(`Request: ${JSON.stringify(request)}`);
}

Expand Down Expand Up @@ -66,6 +72,12 @@ function toRequest(context) {
// this header contains the URL the user requested
const originalUrl = headers['x-ms-original-url'];

// SWA strips content-type headers from empty POST requests, but SK form actions require the header
// https://github.com/geoffrich/svelte-adapter-azure-swa/issues/178
if (method === 'POST' && !body && !headers['content-type']) {
headers['content-type'] = 'application/x-www-form-urlencoded';
}

/** @type {RequestInit} */
const init = {
method,
Expand Down

0 comments on commit d14aae1

Please sign in to comment.