Skip to content

Configuration

Last updated View as MarkdownAgent setup

Previews do not inherit production settings. Define them in the previews block of your configuration file. For how bindings share or isolate data and state, refer to Resources and isolation.

Setting your Previews Base configuration

Define your starting previews block on the branch your team branches from, such as main. Git carries the configuration file into each new branch.

Change the previews block on a branch when its Preview needs different settings. When you run npx wrangler preview, Wrangler uses the configuration file from your current branch as the source of truth. For setup instructions, refer to Get started.

previews on main
varAPP_ENV = "preview"
varAPI_URL = "api.staging.example.com"
bindingUPLOADS = preview-r2-bucket
feature/login
varAPP_ENV = "preview"
varAPI_URL = "api.staging.example.com"
bindingUPLOADS = login-test-r2-bucket
varDEBUG = "true"added
redesign
varAPP_ENV = "preview"
varAPI_URL = "api.staging.example.com"
bindingUPLOADS = preview-r2-bucket
fix-api
varAPP_ENV = "preview"
varAPI_URL = "api.dev.example.com"
bindingUPLOADSremoved

npx wrangler previewuses the configuration file on feature/login as the source of truth

Secrets

Secrets cannot be stored in Wrangler configuration files. To preserve the branching model without applying the same secrets to every Preview manually, set shared secrets once in the Previews Base configuration. Each new Preview receives those secrets when it is created. Set a different value for an individual Preview when needed. Later changes to Base secrets apply only to new Previews, so active Previews remain unchanged.

I want to Command
Add a secret to the Base configuration npx wrangler preview base-config secret put SECRET_NAME
Add a secret to one Preview npx wrangler preview secret put SECRET_NAME --name <preview>
Remove a secret from the Base configuration npx wrangler preview base-config secret delete SECRET_NAME
Remove a secret from one Preview npx wrangler preview secret delete SECRET_NAME --name <preview>

The --name flag defaults to the current git branch if omitted.

Wrangler configuration file

Your Wrangler file has production settings at the top level and Preview settings in a previews block. The previews block is required, but it can be empty if your Preview does not need separate settings. Point Preview bindings at staging or test resources instead of production resources.

{
  // ...
  "vars": {
    "ENVIRONMENT": "production"
  },
  "r2_buckets": [
    {
      "binding": "UPLOADS",
      "bucket_name": "prod-uploads"
    }
  ],
  // ...
  "previews": {
    // ...
    "vars": {
      "ENVIRONMENT": "preview"
    },
    "r2_buckets": [
      {
        "binding": "UPLOADS",
        "bucket_name": "r2-staging"
      }
    ]
    // ...
  }
}
[vars]
ENVIRONMENT = "production"

[[r2_buckets]]
binding = "UPLOADS"
bucket_name = "prod-uploads"

[previews.vars]
ENVIRONMENT = "preview"

[[previews.r2_buckets]]
binding = "UPLOADS"
bucket_name = "r2-staging"

If npx wrangler preview creates a Preview URL but warns that bindings are missing, the URL is live but the runtime configuration is incomplete. Copy the missing bindings into the previews block, using Preview-safe values and test resources. For resource sharing behavior, refer to Resources and isolation.

What goes in the previews block

Use this table to determine where each setting belongs.

SettingBehavior
Top level only
assetsKeep at the top level, even with an ASSETS binding. npx wrangler preview uploads assets from the branch you are previewing.
compatibility_date, compatibility_flagsKeep at the top level.
Top level or previews block
placementTop-level placement applies to Previews. Add previews.placement to override it.
observability, logpush, limitsAdd to previews only if you want Preview-specific values. For observability settings, refer to Test and debug.
Needs a previews block
varsAdd previews.vars with Preview values.
Storage and data bindingsAdd the same binding name, pointed at a Preview-safe resource. Examples: KV, D1, R2, Hyperdrive, Vectorize, Analytics Engine, Pipelines, and Secrets Store.
D1 migrationsConfigure a shared staging database on the base branch. To isolate one branch, update both its Preview binding and migration configuration to use a different database. Apply migrations to the database used by the branch before deploying its Preview.
WorkflowsAdd a binding to an existing Workflow. Previews do not create a Workflow when you change the Workflow name.
Queue producersAdd previews.queues.producers, pointed at a Preview-safe queue.
defineAdd previews.define. Top-level values are not inherited.
tail_consumersAdd previews.tail_consumers. Top-level Tail Worker destinations are not inherited.
Durable ObjectsEach Preview automatically gets a new Durable Object namespace and storage. Keep classes and migrations at the top level. Add previews.durable_objects.bindings only if your code reads the binding from env.
ContainersEach Preview automatically gets a new container app and container instances. Keep migrations at the top level and add container definitions under previews.containers. Keep production container definitions in top-level containers. Add the Durable Object binding under previews only if your code reads the container binding from env.
API bindingsAdd ai, browser, images, stream, media, worker_loaders, or version_metadata under previews if your code reads the binding from env. No staging resource is required.

If your Worker uses only top-level settings, include an empty previews block:

{
  // Set this to today's date
  "compatibility_date": "2026-10-02",
  "assets": {
    "directory": "./public"
  },
  "previews": {}
}
# Set this to today's date
compatibility_date = "2026-10-02"
previews = { }

[assets]
directory = "./public"

Do not add Queue consumers, Cron Triggers, or production routes to previews. These do not target Previews. For Preview hostnames, refer to Custom domains.

Service bindings from a Preview call the bound Worker's production deployment. For more limitations, refer to Limitations.

Dashboard configuration

You can configure Previews Base settings in the dashboard, but you must copy the generated configuration into your Wrangler file. To avoid this extra step, configure your Preview settings in the Wrangler file directly.

  1. In the Cloudflare dashboard, go to Workers & Pages.

    Go to Workers & Pages ↗
  2. Select your Worker.

  3. Go to Settings. The Variables and secrets, Bindings, Observability, and Runtime sections have toggles for Production and Previews Base.

    Settings tab showing Production and Previews Base toggles for variables, secrets, and bindings
  4. Select Previews Base in each section to configure what new Previews start from. You can import names and values from production, then edit them. You must re-enter secrets manually.

    Import dialog showing variables and secrets imported from production to Previews
  5. Update your Wrangler configuration file with the generated previews configuration. This keeps future deployments in sync.

    Dashboard showing generated Wrangler configuration for a Previews Base binding

Was this helpful?