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.
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 mainAPP_ENV = "preview"API_URL = "api.staging.example.com"UPLOADS = preview-r2-bucketAPP_ENV = "preview"API_URL = "api.staging.example.com"UPLOADS = login-test-r2-bucketDEBUG = "true"addedAPP_ENV = "preview"API_URL = "api.staging.example.com"UPLOADS = preview-r2-bucketAPP_ENV = "preview"API_URL = "api.dev.example.com"UPLOADSremovednpx wrangler previewuses the configuration file on feature/login as the source of truth
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.
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.
Use this table to determine where each setting belongs.
| Setting | Behavior |
|---|---|
| Top level only | |
assets | Keep at the top level, even with an ASSETS binding. npx wrangler preview uploads assets from the branch you are previewing. |
compatibility_date, compatibility_flags | Keep at the top level. |
Top level or previews block | |
placement | Top-level placement applies to Previews. Add previews.placement to override it. |
observability, logpush, limits | Add to previews only if you want Preview-specific values. For observability settings, refer to Test and debug. |
Needs a previews block | |
vars | Add previews.vars with Preview values. |
| Storage and data bindings | Add the same binding name, pointed at a Preview-safe resource. Examples: KV, D1, R2, Hyperdrive, Vectorize, Analytics Engine, Pipelines, and Secrets Store. |
| D1 migrations | Configure 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. |
| Workflows | Add a binding to an existing Workflow. Previews do not create a Workflow when you change the Workflow name. |
| Queue producers | Add previews.queues.producers, pointed at a Preview-safe queue. |
define | Add previews.define. Top-level values are not inherited. |
tail_consumers | Add previews.tail_consumers. Top-level Tail Worker destinations are not inherited. |
| Durable Objects | Each 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. |
| Containers | Each 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 bindings | Add 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.
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.
-
In the Cloudflare dashboard, go to Workers & Pages.
Go to Workers & Pages ↗ -
Select your Worker.
-
Go to Settings. The Variables and secrets, Bindings, Observability, and Runtime sections have toggles for Production and Previews Base.
-
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.
-
Update your Wrangler configuration file with the generated
previewsconfiguration. This keeps future deployments in sync.