Cloudflare DevelopersCD
Cloudflare Developers2y ago
13 replies
jason

I'm using Cloudflare Pages with KV.

I'm using Cloudflare Pages with KV.

My goal is to set up KV for different environments, to have:
1. one KV id for production, and
2. another KV id for all other environments (preview URLs, local dev with miniflare maybe, etc)

The docs show two approaches:

v1
kv_namespaces = [
  { binding = "KV", id = "abc123", preview_id = "xyz456" }
]


OR

v2 (using environments)
kv_namespaces = [
  { binding = "MY_KV", id = "abc123" }
]

[env.production]
route = "example.com/*"
kv_namespaces = [
  { binding = "MY_KV", id = "xyz456" }
]


- which is preferred and why?
- for the first version, how does Cloudflare differentiate when to use the KV represented by
id
or preview_id?
Was this page helpful?