Search code examples
fetchmiddlewaresveltekitintercept

How to write SvelteKit middleware or interceptor for fetch both on server and client?


As title says, how to you write middleware in SvelteKit? I know to do it in hooks.server.ts.

I succeed to intercept server requests, but it would be ideal to make interceptor or middleware for both client and server calls in SvelteKit.


Solution

  • You could potentially handle the fetch event in a service worker (kit docs).