The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev guideRecipesAPI Reference
Dev guideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Deployment guide for Cloudflare Workers

Instructions on deploying Optimizely Edge Agent to Cloudflare Workers.

👍

Beta

Optimizely Edge Agent is in beta. Apply on the Optimizely beta signup page or contact your Customer Success Manager.

Prerequisites

You must install the Wrangler CLI to manage Cloudflare Workers.

Get started

Generate a project

Generate a project using the template hosted on GitHub:

wrangler generate {projectname} REPOSITORY PLACEHOLDER

Configure wrangler.toml file

  1. Rename the wrangler.toml.template file in the root of the project to wrangler.toml.
  2. Update the variables inside by adding your account_id and kv_namespace(s) if you plan on using the KV Store for datafile and flag keys management.

wrangler.toml.template file example:

#:schema node_modules/wrangler/config-schema.json
name = "optly-hybrid-agent"
main = "src/index.js"
compatibility_date = "2024-05-02"
compatibility_flags = ["nodejs_compat"]
account_id = "YOUR ACCOUNT ID HERE"
workers_dev = true
route = "YOUR ROUTE GOES HERE"
kv_namespaces = [
  {
    binding = "OPTLY_HYBRID_AGENT_KV", 
    id = "KV NAMESPACE ID GOES HERE", 
    preview_id = "KV PREVIEW NAMESPACE ID GOES HERE"
  },
  {
    binding = "OPTLY_HYBRID_AGENT_UPS_KV", 
    id = "KV USER PROFILE NAMESPACE ID GOES HERE", 
    preview_id = "KV USER PROFILE PREVIEW NAMESPACE ID GOES HERE"
  }
]

[vars]
# Supported: "debug, debugExt, info, error"
LOG_LEVEL = "debug"
# TESTING_FLAG_DEBUG = "INDIVIDUAL FX FLAG KEY FOR TESTING GOES HERE"

Update Project Configuration

Update the project configuration settings in the requestConfig.js file located in the config directory. See the requestConfig.js documentation for further details.

Install node modules

Install the necessary Node.js modules:

npm install

Test and debug locally

Using Wrangler CLI, you can test and debug the worker locally. This supports local debugging and lets you set breakpoints.

wrangler dev

Visual Studio (VS) Code launch configuration

The following is an example VS Code launch configuration that will attach the VS Code debugger to the local development Cloudflare Edge Worker for debugging purposes.

{  
  "version": "0.2.0",  
  "configurations": \[  
    {  
      "type": "pwa-node",  
      "request": "attach",  
      "name": "Attach to Cloudflare Worker",  
      "skipFiles": ["<node_internals>/**"],  
      "port": 9229,  
      "localRoot": "${workspaceFolder}",  
      "remoteRoot": "/src"  
    }  
  ]  
}

Deploy the Cloudflare Worker

To deploy the Worker to Cloudflare:

wrangler publish

(Optional) Tail Logs for Debugging

To debug and tail the logs when accessing Workers deployed on Cloudflare:

wrangler tail -f pretty

For additional information, see the API reference documentation.