-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expose whether a given event is a real network request or a synthetic fetch during load #10163
Description
Describe the problem
There is not currently a good way to know whether a given event corresponds to a real request coming in to the server, or a synthetic request from load's fetch (or event.fetch) being called for the same origin, which just calls handle without generating a real network request.
This is important to be able to know in my particular use case of having an API gateway that sites in front of both the SvelteKit app and some external API. load fetch requests from the browser can be set to the same origin, but these requests during SSR get sent to handle and I need them to go out to the real API. Right now, I'm doing this when the URL path matches a given regex - however, this could easily match things that aren't really API requests, and if these are ultimately mapped back to the SvelteKit app, this results in an infinite loop.
Describe the proposed solution
A new flag on the event object (say, event.isSyntheticRequest) makes sense to me here.
Alternatives considered
For right now, my plan is to add a dummy x-is-ssr-api-fetch header to the appropriate requests as part of my handleFetch hook, and then in my handle hook look for that header, remove the header, and deal with the request appropriately.
Importance
would make my life easier
Additional Information
We already have event.isDataRequest. I'm not entirely thrilled about the word 'synthetic' here, but I do think some name of the form event.is*Request makes sense here.