From e04340a56fd05b59061d08d5be24500889e25d95 Mon Sep 17 00:00:00 2001 From: Adam Murray Date: Mon, 29 Jan 2024 15:49:02 -0600 Subject: [PATCH 1/3] pages: add sections about local support for bindings in wrangler.toml to d1, r2, kv, and service bindings docs --- content/pages/functions/bindings.md | 40 ++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/content/pages/functions/bindings.md b/content/pages/functions/bindings.md index cba2273006bd44..8ed9af01bca9ee 100644 --- a/content/pages/functions/bindings.md +++ b/content/pages/functions/bindings.md @@ -55,6 +55,14 @@ export const onRequest: PagesFunction = async (context) => { While developing locally, interact with your KV namespace by adding `-k ` or `--kv=` to your run command. For example, if your namespace is bound to `TODO_LIST`, access the KV namespace in your local dev by running `npx wrangler pages dev --kv=TODO_LIST`. The data from this namespace can be accessed using `context.env.TODO_LIST`. +Alternatively, you can interact with a KV namespace locally via a `wrangler.toml` file. See [Wrangler configuration](/workers/wrangler/configuration/#kv-namespaces) for more information. + +{{}} + ## Durable Object namespaces [Durable Objects](/durable-objects/) (DO) are Cloudflare's strongly consistent data store that power capabilities such as connecting WebSockets and handling state. To bind your DO namespace to your Pages Function: @@ -147,7 +155,21 @@ export const onRequest: PagesFunction = async (context) => { ### Interact with your R2 buckets locally -While developing locally, interact with an R2 bucket by adding `--r2=` to your run command. For example, if your bucket is bound to `BUCKET`, access this bucket in local dev by running `npx wrangler pages dev --r2=BUCKET`. Interact with this binding by using `context.env` (for example, `context.env.BUCKET`). +While developing locally, interact with an R2 bucket by adding `--r2=` to your run command. + +{{}} + +If your bucket is bound to `BUCKET`, access this bucket in local dev by running `npx wrangler pages dev --r2=BUCKET`. Interact with this binding by using `context.env` (for example, `context.env.BUCKET`). + +Alternatively, you can interact with an R2 bucket locally via a `wrangler.toml` file. See [Wrangler configuration](/workers/wrangler/configuration/#r2-buckets) for more information. + +{{}} ## D1 databases @@ -207,6 +229,14 @@ Specifically: Refer to the [D1 client API documentation](/d1/how-to/query-databases/) for the API methods available on your D1 binding. +Alternatively, you can interact with a D1 database locally via a `wrangler.toml` file. See [Wrangler configuration](/workers/wrangler/configuration/#d1-databases) for more information. + +{{}} + ## Workers AI [Workers AI](/workers-ai/) allows you to run powerful AI models. To bind Workers AI to your Pages Function: @@ -306,6 +336,14 @@ export const onRequest: PagesFunction = async (context) => { To interact with a [service binding](/workers/configuration/bindings/about-service-bindings/) while developing locally, run the Worker you want to bind to via `wrangler dev` and in parallel, run `wrangler pages dev` with `--service =` where `SCRIPT_NAME` indicates the name of the Worker. For example, if your Worker is called `my-worker`, connect with this Worker by running it via `npx wrangler dev` (in the Worker's directory) alongside `npx wrangler pages dev --service MY_SERVICE=my-worker` (in the Pages' directory). Interact with this binding by using `context.env` (for example, `context.env.MY_SERVICE`). +Alternatively, you can interact with a service binding locally via a `wrangler.toml` file. See [Wrangler configuration](/workers/wrangler/configuration/#service-bindings) for more information. + +{{}} + ## Queue Producers [Queue Producers](/queues/reference/javascript-apis/#producer) enable you to send messages into a Queue within your Pages Function. To add a Queue producer binding to your Pages Function: From d589f5a2ee9474c5cc6069b3f9146a9076e16521 Mon Sep 17 00:00:00 2001 From: Kate Tungusova <70746074+deadlypants1973@users.noreply.github.com> Date: Wed, 14 Feb 2024 17:41:13 +0000 Subject: [PATCH 2/3] Apply suggestions from code review PCX --- content/pages/functions/bindings.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/content/pages/functions/bindings.md b/content/pages/functions/bindings.md index 8ed9af01bca9ee..e971a1375e51c7 100644 --- a/content/pages/functions/bindings.md +++ b/content/pages/functions/bindings.md @@ -55,7 +55,7 @@ export const onRequest: PagesFunction = async (context) => { While developing locally, interact with your KV namespace by adding `-k ` or `--kv=` to your run command. For example, if your namespace is bound to `TODO_LIST`, access the KV namespace in your local dev by running `npx wrangler pages dev --kv=TODO_LIST`. The data from this namespace can be accessed using `context.env.TODO_LIST`. -Alternatively, you can interact with a KV namespace locally via a `wrangler.toml` file. See [Wrangler configuration](/workers/wrangler/configuration/#kv-namespaces) for more information. +Alternatively, you can interact with a KV namespace locally via a `wrangler.toml` file. Refer to [Wrangler configuration](/workers/wrangler/configuration/#kv-namespaces) for more information. {{