dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Cloudflare Pages / Workers integration

Open itsezc opened this issue 1 year ago • 2 comments

Specific Demand

It's easy to build static sites and CSR with Dioxus and have it built ready to go on multiple platforms including Cloudflare Pages, however this is not easily possible with SSR, as Cloudflare uses workerd, a custom JS runtime, which also supports Rust.

It'd be great if fullstack applications with Dioxus can run on CF pages / workers runtimes. Cloudflare is currently the largest runtime platform behind AWS Lambda, with it continuously growing thanks to its amazing pricing.

Implement Suggestion

Perhaps the internal macros for SSR could also generate the necessary code to turn it with workers-rs.

Reference: https://github.com/cloudflare/workers-rs

itsezc avatar Jan 14 '24 08:01 itsezc

It's easy to build static sites and CSR with Dioxus and have it built ready to go on multiple platforms including Cloudflare Pages, however this is not easily possible with SSR, as Cloudflare uses workerd, a custom JS runtime, which also supports Rust.

Dioxus ssr doesn't assume anything about your runtime. It just takes a component, or a block of rsx and renders it to a string. You can hook up dioxus-ssr to a framework of your choice with this guide.

Dioxus fullstack doesn't assume much about your runtime, but it does includes adapters for different frameworks. Worker-rs could be supported through a new adapter or just through an agnostic adapter that takes a generic hyper request and returns a generic hyper response without a router

ealmloff avatar Jan 14 '24 15:01 ealmloff

It's easy to build static sites and CSR with Dioxus and have it built ready to go on multiple platforms including Cloudflare Pages, however this is not easily possible with SSR, as Cloudflare uses workerd, a custom JS runtime, which also supports Rust.

Dioxus ssr doesn't assume anything about your runtime. It just takes a component, or a block of rsx and renders it to a string. You can hook up dioxus-ssr to a framework of your choice with this guide.

Dioxus fullstack doesn't assume much about your runtime, but it does includes adapters for different frameworks. Worker-rs could be supported through a new adapter or just through an agnostic adapter that takes a generic hyper request and returns a generic hyper response without a router

Good to hear this, however where Cloudflare Pages are concerned I believe there might be some additional overhead as can be seen on here:

  • https://developers.cloudflare.com/pages/functions/
  • https://blog.cloudflare.com/pages-functions-with-webassembly

Ultimately when functions are implemented for Cloudflare Pages which takes precedence where Dioxus fullstack is concerned, we could create a guide on: https://developers.cloudflare.com/pages/framework-guides/

itsezc avatar Jan 14 '24 15:01 itsezc