Skip to content
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

Use Sveltekit and worktop together? #147

Closed
jaymakes11 opened this issue Feb 15, 2022 · 2 comments
Closed

Use Sveltekit and worktop together? #147

jaymakes11 opened this issue Feb 15, 2022 · 2 comments

Comments

@jaymakes11
Copy link

Is it possible to use Sveltekit and worktop together? Can anyone point to any example repos?

The only way I can conceptualize approaching this is to create them as separate apps. The worktop (Cloudflare/backend) layer would live on its own (e.g. api.myapp.com or myapp.com/api) and the Sveltekit layer would live on its own (e.g. myapp.com). In Sveltekit, all Cloudflare-specific interaction with things like KV would happen via HTTP. Locating the worktop app in a subfolder rather than a subdirectory would reduce the number of HTTP calls needed due to CORs, though it's not clear to me how to actually build it into a subdirectory of the Sveltekit site (maybe a placeholder route-file in Sveltekit would be needed to be the glue between the two?).

While that approach should work, would it not be preferable to avoid the extra HTTP calls and access KV directly from Sveltekit (via SSR)? Is this even possible with worktop?

For context, after reading https://blog.cloudflare.com/production-saas-intro/ I was left wondering what the intended/preferred/suggested architecture is when using worktop and Svelte (and I assume Sveltekit) together, though perhaps the idea for https://github.com/cloudflare/production-saas is to use Svelte directly and not via Sveltekit.


BTW: Just finished watching Building Svelte Society: The start of a CMS with Luke Edwards which was a super helpful introduction to worktop. Thanks for the promising work here!

@lukeed
Copy link
Owner

lukeed commented Feb 15, 2022

I would build out two separate projects: api.*.com as your worktop app and *.com as your SK app that, during prefetch/load, makes requests to your API. This also gives you the freedom/confidence/control of building specifically a Worker and lean into all its offerings, rather than building on top of an (albeit powerful) abstraction that doesn't fully expose underlying platforms so that it can remain agnostic to all runtimes.

You could use Worktop directly inside a SK app, but you would likely be using utilities Worktop offers instead of its router, which means you also miss out on all the TypeScript strictness it offers too. This is because SvelteKit is the router and is passing around requests and contexts... the same thing Worktop is doing,

The production-saas project will use Svelte, not Svelte Kit, directly. A lot of this has to do with the reasons shared above, but also because it gives far more control in the user's hands, which is ideal for educational purposes but also project longevity and project customizability ... and the intent of production-saas is to be a springboard for your own project – and owning/revealing all the code helps with that goal.

Hope that helps~!

@lukeed lukeed closed this as completed Feb 15, 2022
@jaymakes11
Copy link
Author

Yes, that's very helpful input, @lukeed.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants