Are KV service bindings compatible with Remix Pages?
Following the example on https://developers.cloudflare.com/pages/functions/bindings it is not clear to me how the Remix Pages
functions/[[path]].ts
works with this example. I also attempted to add directly via Wrangler following this page https://developers.cloudflare.com/kv/get-started/#2-create-a-kv-namespace but got an error running npx wrangler kv namespace create BINDING_NAME
with message [ERROR] Unknown arguments: kv, namespace, create, BOOKLISTS_KV
Cloudflare Docs
Bindings | Cloudflare Pages docs
A binding enables your Pages Functions to interact with resources on the Cloudflare developer platform. Use bindings to integrate your Pages Functions with Cloudflare resources like KV, Durable Objects, R2, and D1. You can set bindings for both production and preview environments.
Cloudflare Docs
Get started | Cloudflare Workers KV
Workers KV provides low-latency, high-throughput global storage to your Cloudflare Workers applications. Workers KV is ideal for storing user configuration data, routing data, A/B testing configurations and authentication tokens, and is well suited for read-heavy workloads.
9 Replies
You us the Remix loader functions to do server side stuff like normal and the context has access to bindings through
cloudflare.env
So e.g, context.cloudflare.env.KV
https://developers.cloudflare.com/pages/framework-guides/deploy-a-remix-site/#binding-resources-in-local-developmentI see. A lot here to dig into getting this working but the gist seems to be, correct me if wrong --
- leave the C3 generated
functions/[[path.ts]]
alone
- setup special Vite Cloudflare platform proxy config
- add binding via Wrangler
- use bindings in Remix's loader/actions functions from Context
Thanks Daniel 🙇for 2, you shouldn't need to do anything special afaik - i think it's just auto ready
but yeah, otherwise you basically just use Remix like normal but with Cloudflare's little bit of flavour
Oh, then should we expect to be able to create the KV and add? Referring to https://developers.cloudflare.com/kv/get-started/#2-create-a-kv-namespace
throws an error
I think the overarching tricky element here is weaving through the docs for the Remix-specific scenarios which have nuance given the
functions/[[path.ts]]
Workerwhat is your wrangler version?
That looks old
TIL
npx
does not run latest.
Success after installing wrangler locally (which is not my preferred method of global libraries) and running the same kv namespace create
🎉 Thanks!I think it's worth running it by docs team cause "You configure..." sounds like an instruction, not an FYI in this context which is why I thought #2 was necessary above that you pointed out isn't needed
cc @Denise 😇