components-contrib/internal/component/cloudflare/worker-src
ItalyPaleAle 4e17e42818 CF Worker: better detection for binding type
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
2022-12-29 00:28:16 +00:00
..
lib Add Cloudflare KV state store 2022-12-13 01:52:06 +00:00
.gitignore Refactored to use a shared package 2022-12-13 00:32:55 +00:00
.prettierrc.yaml Added draft code for the Worker 2022-12-10 00:51:47 +00:00
README.md Workers KV: add TTL support 2022-12-19 18:50:59 +00:00
package-lock.json CF Worker: better detection for binding type 2022-12-29 00:28:16 +00:00
package.json CF Worker: better detection for binding type 2022-12-29 00:28:16 +00:00
tsconfig.json WIP 2022-12-12 20:06:04 +00:00
worker.ts CF Worker: better detection for binding type 2022-12-29 00:28:16 +00:00
wrangler.toml Add Cloudflare KV state store 2022-12-13 01:52:06 +00:00

README.md

Dapr connector for Cloudflare Workers

This folder contains the source code for the Worker that is used by Dapr components to interact with Cloudflare services such as KV and Queues.

Version

If you make changes to the Worker, please change the version number in the package.json file. The code is versioned by date in the YYYYMMDD format.

Build code

The built Worker resides in ../workers/code. You can build it with:

npm ci
npm run build

Important: do not publish this worker (e.g. with npx wrangler publish), as it should not use the config in the wrangler.toml file!

Develop locally

Note that when running locally, authorization is not required and all Authorization headers are ignored. Settings for development are read from the wrangler.toml file, which is not used by Dapr.

Create a Queue

The default configuration in wrangler.toml (used for development only) includes a binding to a Queue called daprdemo. If you don't have it already, make sure to create it with:

npx wrangler queues create daprdemo

Create a KV namespace

To test with KV, you need to first create a namespace with Wrangler, for example:

npx wrangler kv:namespace create daprkv
npx wrangler kv:namespace create daprkv --preview

The output contains something like:

Add the following to your configuration file in your kv_namespaces array:
{ binding = "daprkv", id = "......" }
Add the following to your configuration file in your kv_namespaces array:
{ binding = "daprkv", preview_id = "......" }

Make sure to add the values of id and preview_id above to the wrangler.toml file.

Start the application locally

Start the application locally, using Wrangler

npm ci
npm run start

Info endpoint

curl "http://localhost:8787/.well-known/dapr/info"

Using KV

Store a value:

# Format is /kv/<KV namespace>/<key>
curl -X POST -d 'Hello world!' "http://localhost:8787/kv/daprkv/mykey"
# Success: 201 (Created), empty body

Retrieve a value:

# Format is /kv/<KV namespace>/<key>
curl "http://localhost:8787/kv/daprkv/mykey"
# Success: 200 (OK), value in body
# No key: 404 (Not found), empty body

Delete a value:

# Format is /kv/<KV namespace>/<key>
curl -X DELETE "http://localhost:8787/kv/daprkv/mykey"
# Success: 204 (No content), empty body

Using Queues

Publish a message:

# Format is /queues/<queue name>
curl -X POST -d 'orders.42' "http://localhost:8787/queues/daprdemo"
# Success: 201 (Accepted), empty body