You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got bit of a 'weird' scenario where I'd like to access the platform context in a PageLoad handler if it's running on the server in order to get per request platform dependencies.
I've got a store using Shopify and it's storefront API which has per IP/Application rate limiting. This makes it desirable for server side PageLoad handlers to have their data cached for some time to adhere to the rate limits and still serve pages. Normally a cache of some form would be available from a module but the sites hosted on CloudFlare which provides it's key value/cache service per request.
As a workaround I've assigned the cache object to a module variable hoping it's stable between requests but this seems a bit "against the grain".
Have thought about using PageServerLoad but this isn't desirable because the queries don't need to run on the server outside of SSR.
Any suggestions on how to achieve this or alternatives would greatly appreciated as I'm a bit stumped 😅
Edit: The workaround doesn't work in the case of CloudFlare's ExecutionContext/waitUntil.
Seems it would be possible to extend the servers load_data and the LoadData interface to include the server event's platform (and locals) but that would make properties on the event that aren't present on the client which isn't a uniform interface between client and server anymore. Maybe platform and locals can be passed from load_data but not added to the type's so that they're only there if you actually need the 'escape hatch'?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've got bit of a 'weird' scenario where I'd like to access the platform context in a PageLoad handler if it's running on the server in order to get per request platform dependencies.
I've got a store using Shopify and it's storefront API which has per IP/Application rate limiting. This makes it desirable for server side PageLoad handlers to have their data cached for some time to adhere to the rate limits and still serve pages. Normally a cache of some form would be available from a module but the sites hosted on CloudFlare which provides it's key value/cache service per request.
As a workaround I've assigned the cache object to a module variable hoping it's stable between requests but this seems a bit "against the grain".Have thought about using
PageServerLoad
but this isn't desirable because the queries don't need to run on the server outside of SSR.Any suggestions on how to achieve this or alternatives would greatly appreciated as I'm a bit stumped 😅
Edit: The workaround doesn't work in the case of CloudFlare's ExecutionContext/waitUntil.
Seems it would be possible to extend the servers
load_data
and theLoadData
interface to include the server event's platform (and locals) but that would make properties on the event that aren't present on the client which isn't a uniform interface between client and server anymore. Maybe platform and locals can be passed from load_data but not added to the type's so that they're only there if you actually need the 'escape hatch'?Beta Was this translation helpful? Give feedback.
All reactions