Cloudflare Worker
This document describes integrating with the Spec Platform through a Cloudflare worker.
Prerequisites
Please ensure that your development environment has the following dependencies installed with the latest version:
Follow Cloudflare’s “Get started guide” to install Wrangler in your development environment.
This is the Cloudflare Workers command-line interface, which allows you to create, edit, and publish Workers projects to your Cloudflare account.
Following installation, authenticate wrangler.
A TypeScript or JavaScript project to install.
The Spec Worker Library for Cloudflare.
Check out the configuration options for the Spec Platform in Config.
Instructions
Configure a new project with Wrangler, or open an existing project.
Install NPM Spec Proxy Cloudflare Worker into project:
npm i –save @specprotected/spec-proxy-cloudflare-worker
Open
index.ts
file and copy the worker code from the Prerequisites.Publish the worker. Open a terminal window and run
wrangler publish
Configuring Worker Route
With the worker published, we can now use the Cloudflare admin console to configure a route that will use the Spec worker code.
Click "Workers" from Cloudflare sidebar
Select the newly published worker, and find the "Triggers" section.
Click "Add Route" to add a new route for the worker.
Enter URL that matches the traffic path you would like to send to Spec
Select zone that pertains to the domain for your project.
Add route.
The Spec Cloudflare Worker is now live!
Spec Worker Library
If no existing workers exist, the following is Spec's recommended worker code. If there are existing workers, Spec's Product Success will assist in merging the following code with your existing code.
Worker Example
Check Edge Workers page for configuration options.
Last updated