This guide explains how to create a new Cloudflare Worker-based API/search connection for a Webflow project in WCH.
1. Create a New Cloudflare Worker
In Cloudflare, create a new Worker.
Copy the code from an existing Flex Cloudflare Worker and paste it into the new Worker.
2. Add Worker Environment Variables
In the Worker settings, add the following variables:
| Variable | Value |
|---|---|
WEBFLOW_SITE_ID |
The Webflow site ID for the project |
WEBHOOK_SECRET |
The webhook secret used to verify webhook requests |
WEBFLOW_API_KEY |
The Webflow API token |
3. Create a Webflow API Token
Create a Webflow API token with the following scopes:
| Scope | Permission |
|---|---|
| CMS | cms:read |
| Sites | sites:read |
| Pages | pages:read |
Add the generated API token to the Worker settings as: WEBFLOW_API_KEY
4. Add a Webflow Webhook
In the Webflow project, add a webhook pointing to the new Worker endpoint:
https://wchsearch[custom_name].edgarallan.com/webhook
Replace [custom_name] with the project-specific name.
5. Add the Worker Domain
In Cloudflare, add a custom domain or route for the Worker.
Use this route pattern: wchsearch[custom_name].edgarallan.com/*
Turn on Preview URLs for the Worker.
6. Configure DNS
Add the following DNS record:
| Type | Name | Target | Proxy | TTL |
|---|---|---|---|---|
| CNAME | wchsearch | wch-search-app.witt-185.workers.dev | Proxied | Auto |
7. Create a D1 Database
Create a new Cloudflare D1 database for this search connection.
To match the existing schema:
- Open the existing Flex D1 database.
- Go to the relevant table.
- Use Copy Table Schema.
- Open the new D1 database.
- Paste and run the copied schema.
8. Bind the D1 Database to the Worker
In the Worker settings, add a D1 database binding:
| Setting | Value |
|---|---|
| Variable name | db |
| Database | Select the newly created D1 database |
9. Populate or Update the Database
Run the webhook manually to populate or update the D1 database:
curl -X POST https://wchsearch[custom_name].edgarallan.com/webhook
If successful, the Worker will sync the Webflow CMS/pages data into the D1 database.