-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix parsing endpoint json body (#1272)
* fix parsing endpoint json body Converting to JSON string also when the 'content-type' header is 'application/json' prevents the endpoint from functioning as a relay, that is, it can't fetch an API that returns a JSON string and then forwards the headers and the body as they are, because svelte kit would call JSON.stringify on the string again. * Do call JSON.stringify if the body is not string and header denotes json
- Loading branch information
Showing
6 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
Not calling JSON.stringify on endpoint's body if it's a string and the content-type header denotes json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function get() { | ||
return { | ||
headers: { | ||
'content-type': 'application/json' | ||
}, | ||
body: '42' | ||
}; | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/kit/test/apps/basics/src/routes/load/relay.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script context="module"> | ||
/** @type {import('@sveltejs/kit').Load} */ | ||
export async function load({ fetch }) { | ||
const res = await fetch('/load/relay.json'); | ||
return { | ||
props: { | ||
answer: await res.json() | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<script> | ||
export let answer; | ||
</script> | ||
|
||
<h1>{answer}</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ | |
export let answer; | ||
</script> | ||
|
||
<h1>{answer}</h1> | ||
<h1>{answer}</h1> |