Git Product home page Git Product logo

cloudworker's Introduction


⚠️ Cloudworker is no longer actively maintained at Dollar Shave Club. If you're interested in volunteering to help, please open an issue ⚠️

Cloudworker allows you to run Cloudflare Worker scripts locally.

Installing

Install via NPM:

npm install -g @dollarshaveclub/cloudworker

Package Usage

const Cloudworker = require('@dollarshaveclub/cloudworker')

const simpleScript = `addEventListener('fetch', event => {
  event.respondWith(new Response('hello', {status: 200}))
})`

const req = new Cloudworker.Request('https://myfancywebsite.com/someurl')
const cw = new Cloudworker(simpleScript)
cw.dispatch(req).then((res) => {
  console.log("Response Status: ", res.status)
  res.text().then((body) =>{
    console.log("Response Body: ", body)
  })
})

CLI Usage

Usage: cloudworker [options] <file>

Options:
  -p, --port <port>                   Port (default: 3000)
  -d, --debug                         Debug
  -s, --kv-set [variable.key=value]   Binds variable to a local implementation of Workers KV and sets key to value (default: [])
  -f, --kv-file [variable=path]       Set the filepath for value peristence for the local implementation of Workers KV (default: [])
  -w, --wasm [variable=path]          Binds variable to wasm located at path (default: [])
  -c, --enable-cache                  Enables cache <BETA>
  -r, --watch                         Watch the worker script and restart the worker when changes are detected
  -h, --help                          output usage information

Simple

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

Workers KV

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

Workers KV with Persistence

cloudworker --debug --kv-file KeyValueStore=kv.json --kv-set KeyValueStore.key=value --kv-set KeyValueStore.hello=world example/example-kv.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.

Release Process

For beta releases:

  • Create a new release branch named v[version]-beta. e.g. v0.0.10-beta
  • Run npm version [version]-beta.[beta number]. e.g npm version 0.0.10-beta.1
  • Push branch to origin.
  • Run npm publish --tag beta.
  • Create a new release in Github using tag created by npm version, write relevant release notes, and ensure "This is a pre-release" is checked.
  • Bug fixes and changes should be made on feature branches, merged into master, and then merged into the release branch.
  • Subsequent beta releases of the same beta version should be made off of the same release branch.

For production releases:

  • Merge release branch (if one exists) into master.
  • Run npm version [version]. e.g. npm version 0.0.10
  • Push master to origin.
  • Run npm publish.
  • Create a new release in Github using tag created by npm version and copy release notes from beta.

License

MIT

cloudworker's People

Contributors

atmin avatar bkeroackdsc avatar danzlarkin avatar gregbrimble avatar hankjacobs avatar inyono avatar jboulter avatar jdanyow avatar kamal avatar kturney avatar richardkazuomiller avatar timdp avatar tootedom 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.