Skip to content

xrpl-mm/leptos-cloudflare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

leptos-cloudflare

Leptos SSR with workers-rs backend, deployed directly to Cloudflare using wrangler.

Prerequisites

Install wrangler:

npm i -g wrangler

Install wasm-pack:

curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

Local development

Run inside example directory:

wrangler dev

Then access the website on localhost.

Deployment

Run inside example directory:

wrangler deploy

inside worker directory. This will deploy Workers Sites.

How it works

Client-side rendered code in lib.rs gets compiled first by running wasm-pack build --target=web -- --features hydrate --no-default-features.

Then, everything related to server-side rendering in main.rs gets compiled by running worker-build --release -- --features ssr --no-default-features --bin example.

There is no need to run these commands manually; wrangler dev will run them as they are defined in wrangler.toml.

KV storage file name

As with any websites, static files need to be stored somewhere, and Cloudflare offers KV storage as a solution.

For deployment, wrangler will derive hashes from worker site files and append it to the file name before the extension. For example, client_bg.wasm will become client_bg.849eaf9261.wasm.

However, under local development, the file name does not contain a hash. These discrepancies need to be handled. However, workers-rs does not offer such a functionality natively.

There's a related PR at cloudflare/workers-rs#308 but it seems that Cloudflare team is not keen on merging the PR or even integrating this feature into workers-rs repository.

Therefore, a separate fork has been made at https://github.com/9oelM/workers-rs/commit/00def197b6be6cb43604c7de1fc58523e95b6c84 to install worker-build and to serve as a dependency of the worker directory.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published