I am fetching the data in my +page.ts
file like this:
import type { UserOverview } from '$lib/types/user';
import type { PageLoad } from './$types';
export const load = (async ({ fetch}) => {
let entryCount: number;
const users: UserOverview[] = await fetch("<Url>", {
method: 'GET',
credentials: 'include'
})
.then((r) => {
entryCount = parseInt(r.headers.get('X-Total-Count') as string);
return r.json();
});
return {
users,
entryCount
};
}) satisfies PageLoad;
so that i can access the entryCount in my +page.svelte
.
On SSR the X-Total-Count
wasn't present, so I added this code to my hooks.server.ts
file.
import type { Handle } from '@sveltejs/kit';
export const handle = (async ({ event, resolve }) => {
return resolve(event, {
filterSerializedResponseHeaders: (name) => name.startsWith('x')
});
}) satisfies Handle;
And it works now on SSR.
However on CSR, the header X-Total-Count
is not present in the load function.
As the docs state filterSerializedResponseHeaders
only exists as a server hook.
The API response (dev-tools) does include the header, but it does not show up in the load function.