How SvelteKit endpoints are handled
Hi there!
Does SvelteKit server routes are handled as a Cloudflare Worker? (I mean do I need to pay attention to Node-dependent libs when writing SvelteKit server routes)
SvelteKit server routes doc: https://kit.svelte.dev/docs/routing
Using SvelteKit functions on Cloudflare Pages doc: https://developers.cloudflare.com/pages/framework-guides/deploy-a-svelte-site/#functions-setup
SvelteKit docs
Routing • SvelteKit documentation
Deploy a Svelte site · Cloudflare Pages docs
Svelte is an increasingly popular, open-source framework for building user interfaces and web applications. Unlike most frameworks, Svelte is …
8 Replies
Yes. When deploying to Pages, you only have access to a Node Server at build. So any code running within a SvelteKit Function must be compatible with Workers/Pages Functions.
Thanks for your reply!
But is a SvelteKit server endpoint (function) actually a Worker and can be used to interact with R2 bindings and other Cloudflare features or it just « like » a Worker but not truly one?
All of the Server Endpoints(and SSR-related machinery) are bundled into a single file, which is deployed as a Pages Function.
Pages Functions are Workers, but for Pages. They support most of the stuff that Workers support, including D1, R2, KV bindings, etc.
Thanks for clarification, I wanted to be sure since I don’t pack Server Endpoint or any server-side logic in a /functions folder like it’s shown in the Cloudflare doc
Yeah, SvelteKit, when building, will do that for you
Awesome !
By any chance, have you some examples using R2 bindigns in SvelteKit endpoint ? There are some threads on the Cloudflare forums but it’s unclear how to proprely use bindings with Sveltekit functions (both in prod and local)
Thanks!