Cloudflare
Add the SDK
- 1
Install and authenticate the Cloudflare wrangler utility
Run the following to install globally via
npmand login:terminalnpm install -g wranglerwrangler login - 2
Pull and install the monocle-cloudflare-plugin repository
Clone the monocle cloudflare plugin to your local workspace and install dependencies.
Note: This local setup will house your configuration. It is recommended that you manage this with your own version control or fork monocle to easily pull future updates from Spur.
terminalgit clone https://github.com/spurintel/monocle-plugin-cloudflarecd monocle-plugin-cloudflarenpm install - 3
Configure the worker
In your local repository, you will need to modify the
wrangler.tomlfile for your site and Cloudflare account.- Open the wrangler.toml file in your text editor.
- Copy the example settings here or modify the existing file.
- Save and close.
Note: Ensure that you set the
compatibility_date(today),account_id,zone_id, androute.tomlname = "monocle" # Name of your workermain = "index-spur-managed.js" # Do not change - this is the entry point for the workercompatibility_date = "2025-02-27"account_id = "YOUR_ACCOUNT_ID"workers_dev = false # Set to false to deploy to custom domainroute = { pattern = "*YOUR_DOMAIN_HERE/path/to/protect/*", zone_id = "YOUR_ZONE_ID" } - 4
Configure monocle variables
Return to your terminal and run the following commands to store your App's publishable key and secret key. You will be prompted to provide the values for each. You can copy the values from the Monocle Dashboard and paste them into the terminal when prompted.
terminalwrangler secret put SECRET_KEYwrangler secret put PUBLISHABLE_KEY# This is a unique auto-generated cookie secret.# If you prefer, create a new one: "openssl rand -hex 32"wrangler secret put COOKIE_SECRET_VALUE - 5
Deploy the worker
Run the following command to deploy your cloudflare worker to protect your configured routes:
terminalwrangler deploy
Session-Level Analysis (Optional)
- 6
Session-level analysis
Session-level decryption for Cloudflare Workers is configured through the monocle plugin. Refer to the monocle cloudflare plugin documentation for form enrichment and server-side decryption setup.
Related
- Monocle Assessment — Understand the decrypted assessment payload
- Assessment Decryption — Decryption API and backend decryption options