In the new CF Workers - how do I enable

In the new CF Workers - how do I enable preview within the same Worker? Is it as simple as setting "preview_urls": true, in my wrangler.jsonc? Ok if that's that easy then how do I set up environment variables specific to each env: preview and ... prod?
4 Replies
texan
texan3w ago
you'll want to use wrangler environments for this. you'll set up your non production deploy endpoint to do a versions upload pointing to your env (eg. wrangler versions upload --env staging)
FACELESSMAN
FACELESSMANOP3w ago
Ok, is there a tutorial...or example of this on Github? I can look myself, just wondering if you knew I'll start looking up this stuff via your MCP, maybe I find a path for reference this is my config for testing purposes:
{
"name": "toolhouse-vite-test",
"compatibility_date": "2025-10-08",
"compatibility_flags": ["nodejs_compat"],
"main": "./src/worker/index.ts",
"preview_urls": true,

"assets": {
"directory": "./dist",
"binding": "ASSETS"
},

"observability": {
"enabled": true
},

"upload_source_maps": true,

"env": {
"production": {
"vars": {
"APP_NAME": "orlie-worker",
"API_BASE": "https://api.example.com",
"FEATURE_FLAG": "on"
}
},
"staging": {
"vars": {
"APP_NAME": "orlie-worker",
"API_BASE": "https://api-staging.example.com",
"FEATURE_FLAG": "off"
}
}
}
}
{
"name": "toolhouse-vite-test",
"compatibility_date": "2025-10-08",
"compatibility_flags": ["nodejs_compat"],
"main": "./src/worker/index.ts",
"preview_urls": true,

"assets": {
"directory": "./dist",
"binding": "ASSETS"
},

"observability": {
"enabled": true
},

"upload_source_maps": true,

"env": {
"production": {
"vars": {
"APP_NAME": "orlie-worker",
"API_BASE": "https://api.example.com",
"FEATURE_FLAG": "on"
}
},
"staging": {
"vars": {
"APP_NAME": "orlie-worker",
"API_BASE": "https://api-staging.example.com",
"FEATURE_FLAG": "off"
}
}
}
}
and I push as:
wrangler versions upload --env staging
wrangler versions upload --env production
wrangler versions upload --env staging
wrangler versions upload --env production
but this creates 2 workers
texan
texan3w ago
So you'll need two Workers to manage 2 sets of bindings. there's not a 1:1 equivalent like we have in Pages Wrangler config looks fine, you'll want to configure your production worker's non preview url (in dash) to be using --env staging Shouldnt need to configure anything directly on your staging worker
FACELESSMAN
FACELESSMANOP3w ago
GOT IT

Did you find this page helpful?