npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@weglot/cloudworker

v0.2.1

Published

node.js runner for Cloudflare Workers

Downloads

5

Readme


This package is a fork from dollarshaveclub/cloudworker

Installing

Install via YARN:

yarn add --dev @weglot/cloudworker

Package Usage

const Cloudworker = require("@weglot/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
  --tls-key <tlsKey>                  Optional. Path to encryption key for serving requests with TLS enabled. Must specify --tls-cert when using this option.
  --tls-cert <tlsCert>                Optional. Path to certificate for serving requests with TLS enabled. Must specify --tls-key when using this option.
  --https-port <httpsPort>            Optional. Port to listen on for HTTPS requests. Must specify --tls-cert and --tls-key when using this option. May not be the same value as --port.
  -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