Skip to content

Commit

Permalink
Port over changes from geoffrich#179
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffrich authored and derkoe committed Nov 17, 2024
1 parent 595addf commit db3cba8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions files/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ app.http('sk_render', {
*/
handler: async (httpRequest, context) => {
if (debug) {
context.log(
'Starting request',
httpRequest.method,
httpRequest.headers.get('x-ms-original-url')
);
context.log(`Request: ${JSON.stringify(httpRequest)}`);
}

Expand Down Expand Up @@ -68,6 +73,16 @@ app.http('sk_render', {
function toRequest(httpRequest) {
const originalUrl = httpRequest.headers.get('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 (
httpRequest.method === 'POST' &&
!httpRequest.body &&
!httpRequest.headers.get('content-type')
) {
httpRequest.headers.set('content-type', 'application/x-www-form-urlencoded');
}

/** @type {Record<string, string>} */
const headers = {};
httpRequest.headers.forEach((value, key) => {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit db3cba8

Please sign in to comment.