Skip to content

mackenly/zaraz-context-enricher-template

Repository files navigation

Zaraz Context Enricher Template

Starter template for Cloudflare Zaraz Context Enricher

Overview

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.

Usage

  1. Use this template to create a new repository in your GitHub account.
  2. Clone the repository to your local machine.
  3. npm i to install the dependencies.
  4. Edit the src/index.ts file to add your own logic for enriching the context of your requests.
  5. 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.

Continuous Deployment via Actions

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 the Edit 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.

Resources

License

This project is open source and available under the Apache 2.0. Copyright 2024 Tricities Media Group, LLC.