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
Hello, I’m Allie!
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.
Hugo
HugoOP16mo ago
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?
Hello, I’m Allie!
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.
Hugo
HugoOP16mo ago
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
Hello, I’m Allie!
Yeah, SvelteKit, when building, will do that for you
Hugo
HugoOP16mo ago
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)
Hello, I’m Allie!
export async function POST({ request, platform }) {
const x = platform.env.R2.get('x');
}
export async function POST({ request, platform }) {
const x = platform.env.R2.get('x');
}
Off the top of my head Docs Here, under Bindings
Hugo
HugoOP16mo ago
Thanks!
Want results from more Discord servers?
Add your server