Skip to content

Commit 28cf645

Browse files
fix: avoid cors errors for non-http urls (#13493)
fixes #13362
1 parent 2e6527b commit 28cf645

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

.changeset/forty-crabs-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: avoid simulated CORS errors with non-HTTP URLs

packages/kit/src/runtime/server/page/load_data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
242242
dependency = { response, body: null };
243243
state.prerendering.dependencies.set(url.pathname, dependency);
244244
}
245-
} else {
245+
} else if (url.protocol === 'https:' || url.protocol === 'http:') {
246246
// simulate CORS errors and "no access to body in no-cors mode" server-side for consistency with client-side behaviour
247247
const mode = input instanceof Request ? input.mode : (init?.mode ?? 'cors');
248248
if (mode === 'no-cors') {

packages/kit/src/runtime/server/page/load_data.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ test('errors when no acao header present on cors', async () => {
5858
);
5959
});
6060

61+
test('succeeds when fetching from local scheme', async () => {
62+
const fetch = create_fetch({});
63+
const response = await fetch('data:text/plain;foo');
64+
const text = await response.text();
65+
assert.equal(text, 'foo');
66+
});
67+
6168
test('errors when trying to access non-serialized request headers on the server', async () => {
6269
const fetch = create_fetch({});
6370
const response = await fetch('https://domain-a.com');

0 commit comments

Comments
 (0)