Starter template for Cloudflare Zaraz Context Enricher
Need to enrich the context of your Cloudflare Workers with additional data? This template is a starting point for building a Cloudflare Worker that uses the Zaraz Context Enricher to add additional data to the context of your requests.
Tip
If you need help configuring Zaraz for your project, I am a Cloudflare Zaraz Certified Developer and am available for consulting. Contact me for more information.
- Use this template to create a new repository in your GitHub account.
- Clone the repository to your local machine.
npm i
to install the dependencies.- Edit the
src/index.ts
file to add your own logic for enriching the context of your requests. - After configuring CD (see below), push your changes to GitHub to deploy your worker.
Important
Local development does not currently work with the Zaraz Context Enricher. You must deploy your worker to Cloudflare to test it. This is because the Zaraz context is not passed in within the local development environment.
This template includes a GitHub Actions workflow that will deploy your worker to Cloudflare when you push changes to the main
branch. To configure this workflow, you will need to add the following secrets to your GitHub repository:
CLOUDFLARE_API_TOKEN
: Create a token using theEdit Workers
permission template or open this deeplink to prefill the token permissions.
Alternatively, you can manually npm run deploy
to deploy your worker from your local machine or other CI/CD system.
- Zaraz Context Enricher documentation
- Cloudflare Workers documentation
- Worker Bindings
- Use Service Bindings if you need to send a request to another Worker on the same account
This project is open source and available under the Apache 2.0. Copyright 2024 Tricities Media Group, LLC.