35

GitHub - dollarshaveclub/cloudworker: Run Cloudflare Worker scripts locally

 5 years ago
source link: https://github.com/dollarshaveclub/cloudworker
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

README.md

68747470733a2f2f692e696d6775722e636f6d2f653041736775332e6a7067


Cloudworker allows you to run Cloudflare Worker scripts locally.

Installing

Install via NPM:

npm install -g @dollarshaveclub/cloudworker

Usage

Usage: cloudworker [options] <file>

Options:
  -p, --port <port>              Port (default: 3000)
  -d, --debug                    Debug
  -s, --set [variabe.key=value]  Binds variable to a local implementation of Workers KV and sets key to value (default: [])
  -w, --wasm [variable=path]     Binds variable to wasm located at path (default: [])
  -h, --help                     output usage information

Simple

cloudworker worker.js
curl localhost:3000/
cloudworker --debug worker.js
curl localhost:3000/

Workers KV

cloudworker --debug --set KeyValueStore.key=value --set KeyValueStore.hello=world worker.js
curl localhost:3000/

WebAssembly

Simple

cloudworker --debug --wasm Wasm=example/simple.wasm example/example-wasm-simple.js
curl localhost:3000/

WebAssembly Source

Inverse Square Root

cloudworker --debug --wasm isqrt=example/isqrt.wasm example/example-wasm-isqrt.js
curl localhost:3000/?num=9

WebAssembly Source

Resizer

cloudworker --debug --wasm RESIZER_WASM=example/resizer.wasm example/example-wasm-resizer.js
curl localhost:3000/wasm-demo/dogdrone.png?width=210 # or open in browser

WebAssembly Source

Cloudflare Worker Compatibility

Cloudworker strives to be as similar to the Cloudflare Worker runtime as possible. A script should behave the same when executed by Cloudworker and when run within Cloudflare Workers. Please file an issue for scenarios in which Cloudworker behaves differently. As behavior differences are found, this package will be updated to match the Cloudflare Worker runtime. This may result in breakage if scripts depended on those behavior differences.

License

MIT


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK