Skip to content

Commit d14aae1

Browse files
authored
fix: work around SWA issue with empty form bodies (#179)
* fix: work around SWA issue with empty form bodies * chore: more debug logs
1 parent 9b4d834 commit d14aae1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

files/entry.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ export async function index(context) {
2929
const request = toRequest(context);
3030

3131
if (debug) {
32+
context.log(
33+
'Starting request',
34+
context?.req?.method,
35+
context?.req?.headers?.['x-ms-original-url']
36+
);
37+
context.log(`Original request: ${JSON.stringify(context)}`);
3238
context.log(`Request: ${JSON.stringify(request)}`);
3339
}
3440

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

75+
// SWA strips content-type headers from empty POST requests, but SK form actions require the header
76+
// https://github.com/geoffrich/svelte-adapter-azure-swa/issues/178
77+
if (method === 'POST' && !body && !headers['content-type']) {
78+
headers['content-type'] = 'application/x-www-form-urlencoded';
79+
}
80+
6981
/** @type {RequestInit} */
7082
const init = {
7183
method,

0 commit comments

Comments
 (0)