-
Notifications
You must be signed in to change notification settings - Fork 86
feat(cloudflare): add SvelteKit on Cloudflare Workers guide using Alchemy #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cloudflare): add SvelteKit on Cloudflare Workers guide using Alchemy #271
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also:
import { env } from "cloudflare:workers"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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