Store static assets in Workers KV for Rust-WASM Worker HTTP servers

The command-line program kv-sync, is a build tool that syncs files between a local folder and Workers KV, and generates a small manifest that is published with the worker wasm.

This crate was originally developed to support StaticFileHandler from wasm-service, to add static file support for Rust Worker-based http servers.

Although wrangler does a similar kind of sync for projects configured as a Workers "Site", (and we do reuse a lot of code from wrangler in this implementation), there are a few differences:

Installation

To install kv-sync, cargo install kv-assets, and the program kv-sync will be added to .cargo/bin.

If you want to include the kv-assets library in your project, add a line to Cargo.toml:

`kv-assets = "0.2"`

kv-sync operations

kv-sync does the following:

Adding kv-sync to dev workflow

Run kv-sync at least once before publishing the worker the first time. This will upload the files and generate the manifest.

It is not necessary to run kv-sync again until assets (anything in the public folder changes). If a file in that folder changes, run the following: - kv-sync && wrangler publish - kv-sync --prune The first kv-sync will regnerate the manifest and upload modified files; wrangler publish will publish the code; if publish succeeds, it is safe to run the prune step to remove old assets in KV storage.