App

Cloudflare

Add the SDK

  1. 1
    Install and authenticate the Cloudflare wrangler utility

    Run the following to install globally via npm and login:

    terminal
    npm install -g wrangler
    wrangler login
  2. 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.

    terminal
    git clone https://github.com/spurintel/monocle-plugin-cloudflare
    cd monocle-plugin-cloudflare
    npm install
  3. 3
    Configure the worker

    In your local repository, you will need to modify the wrangler.toml file for your site and Cloudflare account.

    1. Open the wrangler.toml file in your text editor.
    2. Copy the example settings here or modify the existing file.
    3. Save and close.

    Note: Ensure that you set the compatibility_date (today), account_id, zone_id, and route.

    toml
    name = "monocle" # Name of your worker
    main = "index-spur-managed.js" # Do not change - this is the entry point for the worker
    compatibility_date = "2025-02-27"
    account_id = "YOUR_ACCOUNT_ID"
    workers_dev = false # Set to false to deploy to custom domain
    route = { pattern = "*YOUR_DOMAIN_HERE/path/to/protect/*", zone_id = "YOUR_ZONE_ID" }
  4. 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.

    terminal
    wrangler secret put SECRET_KEY
    wrangler 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. 5
    Deploy the worker

    Run the following command to deploy your cloudflare worker to protect your configured routes:

    terminal
    wrangler deploy

Session-Level Analysis (Optional)

  1. 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.