workers limitation and server-side-rendering, data storage and sveltekit. Help me understand please

Hello I have been researching on workers and still haven figured out, if i can use it for a fullstack application. If yes, how can i be able to do it. Also, if so, how does it work? I am struggling to figure it out. 1. When having sveltekit framwork running on pages, does it automatically work some magic with “workers” in the background? (Even without me configuring further into it?) 2. In the end the real question is, can i store data from the static site html “forms”, just as if it were running on a server? If so, is this determined by url paths? Can i use POST? What can i do, what cant i do. What do you recommend for me? Where can i learn more! 🤯🤷 Thanks in advance for helping me understand!
1 Reply
Adi
Adi8mo ago
Hey 👋 Yes you can use workers and Cloudflare pages to run fullstack applications. I don't have a huge amount of knowledge in svelte particularly, but I can maybe give a generic explanation that applies to most of these meta frameworks (Next, Remix, Nuxt, Sveltekit etc) To answer your first question. Tldr, there are two build outputs for most of these apps, a client bundle which has your usual JS, css etc and a server bundle. Most frameworks have adapters for the server bundle that can target different runtimes. E.g Sveltekit has a cloudlfare pages adapter - https://kit.svelte.dev/docs/adapter-cloudflare When you use the adapter for Cloudflare pages in all these frameworks, there is an underlying worker that is built and deployed. This worker handles the SSR + any "server" actions that you run in your app. E.g a lot of the metaframeworks have a way of writing code that runs only on the server (I believe in sveltekit it's the load function). These are usually built out and run within the worker that the adapter generates for you When using Cloudflare pages, try not to worry about what is client vs what is a worker. Just use the framework and it's adapter and everything is handled for you automatically. Now, to answer your second question. Yes you can absolutely save data from static html forms. Just use the regular actions / POST endpoint setup that your framework has. These pieces of code are usually run only on the server (aka your worker). When you use an adapter, it will typically give you a way to use bindings to other Cloudflare resoruces, e.g the sveltekit adapter has docs on this - https://kit.svelte.dev/docs/adapter-cloudflare#bindings It's up to you how you want to store data, but if you're just starting out I'd recommend D1. It's an sqlite database and it can be bound do your pages project very easily. From there you can just make SQL inserts / queries in your action / endpoint. Check out the D1 docs to learn more about it. Here's a link on how to use it with sveltekit - https://developers.cloudflare.com/d1/examples/d1-and-sveltekit/ If you feel like you don't need an SQL database, you can also just use Cloudflare KV - https://developers.cloudflare.com/pages/platform/functions/bindings/#kv-namespaces https://developers.cloudflare.com/kv/ Hopefully that helps and gives some clarity. Feel free to ask if you have any more questions 👍
Want results from more Discord servers?
Add your server
More Posts
Infrequent SSL and reset connection errors serving images through a worker.Hi! I’m using a paid worker to return images through a worker attached to a custom domain (picperf.dCould CF / R2 interfere with legit traffic?i know for a fact i will have a big spike in downloads roughly a week from now. i don't get too muchSince this afternoon Error when deploying all our nuxt applicationsApp: xavi-blog-nuxt-wp.pages.dev 20:00:23.177 Deploying your site to Cloudflare's global networkBuilding a simple spam workerHi there, I am trying to build a simple spam worker which would go through an array of email domainsWhat is the CPU limit for hourly crons?My worker is unbounded, and the cron is running hourly, which I believe means it should have a relatGitHub - rasviitanen/rustysignal: Signal...Hey guys trying to build a Signalling Server with Rust based on this repo: https://github.com/rasviiHackathon: Access to Workers Browser Rendering API neededHey folks, we are currently doing a hackathon and really need access to the Workers Browser RenderinI mean, that's pretty unusual, soI mean, that's pretty unusual, so without a reproduction it would be hard to tell why. There is docuis it possible to cache the responses of a URL, for all requests, even if it’s their first timeIn order to save costs, will it be possible to cache every GET request for a period of time.Where will my Cloudflare pages be served?I'm planning on using cloudflare pages for my static app. But from what REGION will it transfer data