Giter Club home page Giter Club logo

leptos-cloudflare's Introduction

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.

leptos-cloudflare's People

Contributors

9oelm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.