Skip to content

Commit 3e56482

Browse files
committed
chore: add a test on the basic playground
1 parent 58b7526 commit 3e56482

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { HandleClientFetch } from '@sveltejs/kit';
2+
3+
export const handleFetch: HandleClientFetch = async ({ request, fetch }) => {
4+
// You can modify the request here if needed
5+
if (request.url.startsWith(location.origin)) {
6+
request.headers.set('X-Client-Header', 'imtheclient');
7+
}
8+
9+
return await fetch(request);
10+
};

playgrounds/basic/src/routes/+layout.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<a href="/c">/c</a>
1414
<a href="/d">/d</a>
1515
<a href="/e">/e</a>
16+
<a href="/client-fetch">/client-fetch</a>
1617
</nav>
1718

1819
{@render children()}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { PageServerLoad } from './$types';
2+
3+
export const load: PageServerLoad = ({ request }) => {
4+
const client_header = request.headers.get('x-client-header');
5+
console.log('client header:', client_header);
6+
7+
return {
8+
header: client_header
9+
};
10+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
let { data } = $props();
3+
</script>
4+
5+
<p>If you navigate from client-side, you should have an header set by handleFetch:</p>
6+
<div>header: {data.header}</div>

0 commit comments

Comments
 (0)