feat(cloudflare): add SvelteKit on Cloudflare Workers guide using Alchemy#271
feat(cloudflare): add SvelteKit on Cloudflare Workers guide using Alchemy#271sam-goodwin merged 17 commits intoalchemy-run:mainfrom acoyfellow:cloudflare-sveltekit-example
Conversation
- Add SvelteKit resource with Cloudflare adapter integration - Include KV and R2 bindings example - Complete demo with styling and resource access - Follow standard Alchemy example patterns
|
Boom! And now we have SvelteKit 🔥 |
- Import path module for constructing paths - Correct the main entry point to use the SvelteKit adapter's generated path - Clarify comments regarding asset directory and compatibility flags
- Demonstrate API routes - Update Svelte component to reflect updated data structure and improve user experience
| ## Using Cloudflare Bindings | ||
|
|
||
| In your SvelteKit routes, access Cloudflare resources via `platform.env`: | ||
|
|
||
| ```ts | ||
| // +page.server.ts | ||
| export const load = async ({ platform }) => { | ||
| const kvData = await platform?.env?.AUTH_STORE?.get('some-key'); | ||
| const r2Object = await platform?.env?.STORAGE?.get('some-file'); | ||
| return { kvData }; | ||
| }; | ||
| ``` |
There was a problem hiding this comment.
You can also:
import { env } from "cloudflare:workers"There was a problem hiding this comment.
works fine at runtime, but SK's SSR build tries to import it in node which doesn't understand the cloudflare: protocol
I tried using Alchemy's cloudflareWorkersDevEnvironmentShim() plugin, but it only applies during dev (apply: "serve").
Any ideas for making the import work during build, or should we stick with platform.env for SSR routes?
There was a problem hiding this comment.
Oh that's very interesting. Maybe cloudflare's template works around that? Otherwise I don't have a solution. It would need to run it in miniflare.
commit: |
|
@claude please review this PR and provide helpful comments throughout the code. |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
|
That's odd. stderr: "fatal: could not open 'examples/cloudflare-sveltekit/vite.config.ts' for reading: No such file or directory\n" |
Wonder if it it's because it's a fork? |
Adds a full example for deploying SvelteKit apps to Cloudflare Workers with Alchemy