This monorepo provides workers for a credential endpoint and an onpublish handler. There is also an example browser client for Cloudflare PubSub.
- Create a token: https://dash.cloudflare.com/profile/api-tokens
- workers write access
- pubsub write access
- Create a
.dev.vars
file in the root of this repo with your token:
CLOUDFLARE_API_TOKEN=secret-CF-api-key
-
Update <./workers/get-broker-token/wrangler.toml> with your account ID, broker, and namespace.
-
Update <./workers/pubsub-onpublish-worker/wrangler.toml> with your account ID and the broker public keys
- To generate public keys, run
wrangler pubsub broker public-keys YOUR_BROKER --namespace=NAMESPACE_NAME
- Deploy the workers for the first time:
npm deploy -w workers/pubsub-onpublish-worker
npm deploy -w workers/get-broker-token
- Update pubsub config to use the onpublish worker
wrangler pubsub broker update broker --namespace=NAMESPACE_NAME --on-publish-url='https://pubsub-onpublish-worker.WORKER_NAMESPACE.workers.dev
- Add
CLOUDFLARE_API_TOKEN
secret env var to cloudflare web config UI for the get-broker-token worker
- idk what the wrangler command is
- Update client config with your broker, namespace, and the URL of your get-broker-token worker.
- <./apps/chat/src/client.js>
- Run the client
npm run dev -w apps/pubsub-client