Skip to content

Commit b0697fc

Browse files
authored
Update Pages bindings to reflect new dashboard, correct queues documentation, and add Hyperdrive details (#17455)
* Update Pages bindings to reflect new dashboard, correct queues documentation, and add Hyperdrive details * Update src/content/docs/pages/functions/bindings.mdx * Update src/content/docs/pages/functions/bindings.mdx * Update src/content/docs/pages/functions/bindings.mdx * Update src/content/docs/pages/functions/bindings.mdx * Update src/content/docs/pages/functions/bindings.mdx * Update src/content/docs/pages/functions/bindings.mdx * Update src/content/docs/pages/functions/bindings.mdx * Update src/content/docs/pages/functions/bindings.mdx * Update src/content/docs/pages/functions/bindings.mdx * Update src/content/docs/pages/functions/bindings.mdx * Update src/content/docs/pages/functions/bindings.mdx
1 parent ce5811c commit b0697fc

File tree

1 file changed

+55
-35
lines changed

1 file changed

+55
-35
lines changed

src/content/docs/pages/functions/bindings.mdx

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ To configure a KV namespace binding via the Cloudflare dashboard:
2727

2828
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
2929
2. In **Account Home**, select **Workers & Pages**.
30-
3. Select your Pages project > **Settings** > **Functions** > **KV namespace bindings** > **Add binding**.
31-
4. Choose whether you would like to set up the binding in your **Production** or **Preview** environment.
30+
3. Select your Pages project > **Settings**.
31+
4. Select your Pages environment > **Bindings** > **Add** > **KV namespace**.
3232
5. Give your binding a name under **Variable name**.
33-
6. Under **KV namespace**, select your desired namespace. You must repeat steps 5 and 6 for both the **Production** and **Preview** environments.
33+
6. Under **KV namespace**, select your desired namespace.
3434
7. Redeploy your project for the binding to take effect.
3535

3636
Below is an example of how to use KV in your Function. In the following example, your KV namespace binding is called `TODO_LIST` and you can access the binding in your Function code on `context.env`:
@@ -86,10 +86,10 @@ To configure a Durable Object binding via the Cloudflare dashboard:
8686

8787
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
8888
2. In **Account Home**, select **Workers & Pages**.
89-
3. Select your Pages project > **Settings** > **Functions** > **Durable Object bindings** > **Add binding**.
90-
4. Choose whether you would like to set up the binding in your **Production** or **Preview** environment.
89+
3. Select your Pages project > **Settings**.
90+
4. Select your Pages environment > **Bindings** > **Add** > **Durable Object**.
9191
5. Give your binding a name under **Variable name**.
92-
6. Under **Durable Object namespace**, select your desired namespace. You must repeat steps 5 and 6 for both the **Production** and **Preview** environments.
92+
6. Under **Durable Object namespace**, select your desired namespace.
9393
7. Redeploy your project for the binding to take effect.
9494

9595
Below is an example of how to use Durable Objects in your Function. In the following example, your DO binding is called `DURABLE_OBJECT` and you can access the binding in your Function code on `context.env`:
@@ -149,10 +149,10 @@ To configure a R2 bucket binding via the Cloudflare dashboard:
149149

150150
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
151151
2. In **Account Home**, select **Workers & Pages**.
152-
3. Select your Pages project > **Settings** > **Functions** > **R2 bucket bindings** > **Add binding**.
153-
4. Choose whether you would like to set up the binding in your **Production** or **Preview** environment.
152+
3. Select your Pages project > **Settings**.
153+
4. Select your Pages environment > **Bindings** > **Add** > **R2 bucket**.
154154
5. Give your binding a name under **Variable name**.
155-
6. Under **R2 bucket**, select your desired R2 bucket. You must repeat steps 5 and 6 for both the **Production** and **Preview** environments.
155+
6. Under **R2 bucket**, select your desired R2 bucket.
156156
7. Redeploy your project for the binding to take effect.
157157

158158
Below is an example of how to use R2 buckets in your Function. In the following example, your R2 bucket binding is called `BUCKET` and you can access the binding in your Function code on `context.env`:
@@ -220,10 +220,10 @@ To configure a D1 database binding via the Cloudflare dashboard:
220220

221221
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
222222
2. In **Account Home**, select **Workers & Pages**.
223-
3. Select your Pages project > **Settings** > **Functions** > **D1 database bindings** > **Add binding**.
224-
4. Choose whether you would like to set up the binding in your **Production** or **Preview** environment.
223+
3. Select your Pages project > **Settings**.
224+
4. Select your Pages environment > **Bindings** > **Add**> **D1 database bindings**.
225225
5. Give your binding a name under **Variable name**.
226-
6. Under **D1 database**, select your desired D1 database. You must repeat steps 5 and 6 for both the **Production** and **Preview** environments.
226+
6. Under **D1 database**, select your desired D1 database.
227227
7. Redeploy your project for the binding to take effect.
228228

229229
Below is an example of how to use D1 in your Function. In the following example, your D1 database binding is `NORTHWIND_DB` and you can access the binding in your Function code on `context.env`:
@@ -296,10 +296,11 @@ To configure a Vectorize index binding via the Cloudflare dashboard:
296296
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
297297
2. In **Account Home**, select **Workers & Pages**.
298298
3. Choose whether you would like to set up the binding in your **Production** or **Preview** environment.
299-
4. Select your Pages project > **Settings** > **Functions** > **Vectorize index bindings** > **Add binding**.
300-
5. Give your binding a name under **Variable name**.
301-
6. Under **Vectorize index**, select your desired Vectorize index. You must repeat steps 5 and 6 for both the **Production** and **Preview** environments.
302-
7. Redeploy your project for the binding to take effect.
299+
4. Select your Pages project > **Settings**.
300+
5. Select your Pages environment > **Bindings** > **Add** > **Vectorize index**.
301+
6. Give your binding a name under **Variable name**.
302+
7. Under **Vectorize index**, select your desired Vectorize index.
303+
8. Redeploy your project for the binding to take effect.
303304

304305
### Use Vectorize index bindings
305306

@@ -433,8 +434,8 @@ To configure a Workers AI binding via the Cloudflare dashboard:
433434

434435
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
435436
2. In **Account Home**, select **Workers & Pages**.
436-
3. Select your Pages project > **Settings** > **Functions** > **Workers AI bindings** > **Add binding**.
437-
4. Choose whether you would like to set up the binding in your **Production** or **Preview** environment.
437+
3. Select your Pages project > **Settings**.
438+
4. Select your Pages environment > **Bindings** > **Add** > **Workers AI**.
438439
5. Give your binding a name under **Variable name**.
439440
6. Redeploy your project for the binding to take effect.
440441

@@ -505,10 +506,10 @@ To configure a Service binding via the Cloudflare dashboard:
505506

506507
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
507508
2. In **Account Home**, select **Workers & Pages**.
508-
3. Select your Pages project > **Settings** > **Functions** > **Service bindings** > **Add binding**.
509-
4. Choose whether you would like to set up the binding in your **Production** or **Preview** environment.
509+
3. Select your Pages project > **Settings**.
510+
4. Select your Pages environment > **Bindings** > **Add** > **Service binding**.
510511
5. Give your binding a name under **Variable name**.
511-
6. Under **Service**, select your desired Worker. You must repeat steps 5 and 6 for both the **Production** and **Preview** environments.
512+
6. Under **Service**, select your desired Worker.
512513
7. Redeploy your project for the binding to take effect.
513514

514515
Below is an example of how to use Service bindings in your Function. In the following example, your Service binding is called `SERVICE` and you can access the binding in your Function code on `context.env`:
@@ -560,10 +561,10 @@ To configure a queue producer binding via the Cloudflare dashboard:
560561

561562
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
562563
2. In **Account Home**, select **Workers & Pages**.
563-
3. Select your Pages project > **Settings** > **Functions** > **Queue Producers bindings** > **Add binding**.
564-
4. Choose whether you would like to set up the binding in your **Production** or **Preview** environment.
564+
3. Select your Pages project > **Settings**.
565+
4. Select your Pages environment > **Functions** > **Add** > **Queue**.
565566
5. Give your binding a name under **Variable name**.
566-
6. Under **Dataset**, input your desired dataset. You must repeat steps 5 and 6 for both the **Production** and **Preview** environments.
567+
6. Under **Queue**, select your desired queue.
567568
7. Redeploy your project for the binding to take effect.
568569

569570
Below is an example of how to use a queue producer binding in your Function. In this example, the binding is named `MY_QUEUE` and you can access the binding in your Function code on `context.env`::
@@ -610,14 +611,28 @@ If using a queue producer binding with a Pages Function, you will be able to sen
610611

611612
:::note
612613

613-
PostgreSQL drivers like [`Postgres.js`](https://github.com/porsager/postgres) depend on Node.js APIs and as such Functions with Hyperdrive config bindings must be [deployed with Node.js compatibility](/workers/runtime-apis/nodejs).
614+
PostgreSQL drivers like [`Postgres.js`](https://github.com/porsager/postgres) depend on Node.js APIs. Pages Functions with Hyperdrive bindings must be [deployed with Node.js compatibility](/workers/runtime-apis/nodejs).
615+
616+
```toml title="wrangler.toml"
617+
compatibility_flags = [ "nodejs_compat" ]
618+
compatibility_date = "2024-09-23"
619+
```
614620

615621
:::
616622

617623
[Hyperdrive](/hyperdrive/) is a service for connecting to your existing databases from Cloudflare Workers and Pages Functions.
618624

619625
To bind your Hyperdrive config to your Pages Function, you can configure a Hyperdrive binding in [`wrangler.toml`](/pages/functions/wrangler-configuration/#hyperdrive) or the Cloudflare dashboard.
620626

627+
To configure a Hyperdrive binding via the Cloudflare dashboard:
628+
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
629+
2. In **Account Home**, select **Workers & Pages**.
630+
3. Select your Pages project > **Settings**.
631+
4. Select your Pages environment > **Bindings** > **Add** > **Hyperdrive**.
632+
5. Give your binding a name under **Variable name**.
633+
6. Under **Hyperdrive configuration**, select your desired configuration.
634+
7. Redeploy your project for the binding to take effect.
635+
621636
Below is an example of how to use Hyperdrive in your Function. In the following example, your Hyperdrive config is named `HYPERDRIVE` and you can access the binding in your Function code on `context.env`:
622637

623638
<Tabs> <TabItem label="JavaScript" icon="seti:javascript">
@@ -668,7 +683,11 @@ export const onRequest: PagesFunction<Env> = async (context) => {
668683
};
669684
```
670685

671-
</TabItem> </Tabs>
686+
</TabItem> </Tabs>
687+
688+
### Interact with your Hyperdrive binding locally
689+
690+
To interact with your Hyperdrive binding locally, you must provide a local connection string to your database that your Pages project will connect to directly. You can set an environment variable `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING_NAME>` with the connection string of the database, or use the `wrangler.toml` file to configure your Hyperdrive binding with a `localConnectionString` as specified in [Hyperdrive documentation for local development](/hyperdrive/configuration/local-development/). Then, run [`npx wrangler pages dev <OUTPUT_DIR>`](/workers/wrangler/commands/#dev-1).
672691

673692
## Analytics Engine
674693

@@ -680,10 +699,10 @@ To configure an Analytics Engine binding via the Cloudflare dashboard:
680699

681700
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
682701
2. In **Account Home**, select **Workers & Pages**.
683-
3. Select your Pages project > **Settings** > **Functions** > **Analytics Engine bindings** > **Add binding**.
684-
4. Choose whether you would like to set up the binding in your **Production** or **Preview** environment.
702+
3. Select your Pages project > **Settings**.
703+
4. Select your Pages environment > **Bindings** > **Add** > **Analytics engine**.
685704
5. Give your binding a name under **Variable name**.
686-
6. Under **Dataset**, input your desired dataset. You must repeat steps 5 and 6 for both the **Production** and **Preview** environments.
705+
6. Under **Dataset**, input your desired dataset.
687706
7. Redeploy your project for the binding to take effect.
688707

689708
Below is an example of how to use an Analytics Engine binding in your Function. In the following example, the binding is called `ANALYTICS_ENGINE` and you can access the binding in your Function code on `context.env`:
@@ -740,8 +759,8 @@ To configure an environment variable via the Cloudflare dashboard:
740759

741760
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
742761
2. In **Account Home**, select **Workers & Pages**.
743-
3. Select your Pages project > **Settings** > **Environment variables**.
744-
4. Selecting **Add variables** under **Production** and/or **Preview**.
762+
3. Select your Pages project > **Settings**.
763+
4. Select your Pages environment > **Variables and Secrets** > **Add** .
745764
5. After setting a variable name and value, select **Save**.
746765

747766
Below is an example of how to use environment variables in your Function. The environment variable in this example is `ENVIRONMENT` and you can access the environment variable on `context.env`:
@@ -797,10 +816,11 @@ To add secrets to your Pages project:
797816

798817
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
799818
2. In **Account Home**, select **Workers & Pages**.
800-
3. Select your Pages project > select **Settings** > **Environment variables**.
801-
4. Selecting **Add variables** under **Production** and/or **Preview**.
802-
5. Select **Encrypt** to create your secret.
803-
6. Select **Save**.
819+
3. Select your Pages project > select **Settings**.
820+
4. Select your Pages environment > **Variables and Secrets** > **Add**.
821+
5. Set a variable name and value.
822+
6. Select **Encrypt** to create your secret.
823+
7. Select **Save**.
804824

805825
You use secrets the same way as environment variables. When setting secrets with Wrangler or in the Cloudflare dashboard, it needs to be done before a deployment that uses those secrets. For more guidance, refer to [Environment variables](#environment-variables).
806826

0 commit comments

Comments
 (0)