jculveyhouse
jculveyhouse
CDCloudflare Developers
Created by bdematt on 1/8/2024 in #pages-help
Access bindings in dev
I just tried this on a fresh project with npm create cloudflare@latest -- --framework svelte and it seems to be working
7 replies
CDCloudflare Developers
Created by bdematt on 1/8/2024 in #pages-help
Access bindings in dev
Bindings should work in dev out of the box. In late January (not sure of the specific version but can look it up if needed) Svelte changed the Cloudflare adapter to use getBindingsProxy which will automatically emulate any bindings defined in your wrangler.toml when running vite dev in a svelte project
7 replies
CDCloudflare Developers
Created by Brandon Pittman on 4/9/2024 in #pages-help
Setting up bindings for KV and Qwik
Awesome, glad it worked. If you run into any more issue let us know 😄
11 replies
CDCloudflare Developers
Created by Brandon Pittman on 4/9/2024 in #pages-help
Setting up bindings for KV and Qwik
// src/routes/kv-demo/index.ts
import type { RequestHandler } from "@builder.io/qwik-city";

export const onGet: RequestHandler = async ({ platform, json }) => {
const counter = parseInt(
(await platform.env.MY_KV_NAMESPACE.get("count")) || "0"
);
await platform.env.MY_KV_NAMESPACE.put("count", String(counter + 1));

json(200, { counter, success: true });
};
// src/routes/kv-demo/index.ts
import type { RequestHandler } from "@builder.io/qwik-city";

export const onGet: RequestHandler = async ({ platform, json }) => {
const counter = parseInt(
(await platform.env.MY_KV_NAMESPACE.get("count")) || "0"
);
await platform.env.MY_KV_NAMESPACE.put("count", String(counter + 1));

json(200, { counter, success: true });
};
11 replies
CDCloudflare Developers
Created by Brandon Pittman on 4/9/2024 in #pages-help
Setting up bindings for KV and Qwik
If you're starting from scratch, you can run npm create cloudflare@latest -- --framework qwik. Out of the box it will provide a wrangler.toml including bindings examples. Uncomment the KV example and run build-cf-types to regenerate a type definition for the platform object and it will include your KV
11 replies
CDCloudflare Developers
Created by Brandon Pittman on 4/9/2024 in #pages-help
Setting up bindings for KV and Qwik
Can you give await platform.env["MY_KV_NAMESPACE"] a shot?
11 replies