You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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**.
32
32
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.
34
34
7. Redeploy your project for the binding to take effect.
35
35
36
36
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:
86
86
87
87
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
88
88
2. In **Account Home**, select **Workers & Pages**.
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**.
91
91
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.
93
93
7. Redeploy your project for the binding to take effect.
94
94
95
95
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:
149
149
150
150
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
151
151
2. In **Account Home**, select **Workers & Pages**.
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**.
154
154
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.
156
156
7. Redeploy your project for the binding to take effect.
157
157
158
158
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:
220
220
221
221
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
222
222
2. In **Account Home**, select **Workers & Pages**.
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**.
225
225
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.
227
227
7. Redeploy your project for the binding to take effect.
228
228
229
229
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:
296
296
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
297
297
2. In **Account Home**, select **Workers & Pages**.
298
298
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.
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**.
510
511
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.
512
513
7. Redeploy your project for the binding to take effect.
513
514
514
515
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:
560
561
561
562
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
562
563
2. In **Account Home**, select **Workers & Pages**.
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**.
565
566
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.
567
568
7. Redeploy your project for the binding to take effect.
568
569
569
570
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
610
611
611
612
:::note
612
613
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
+
```
614
620
615
621
:::
616
622
617
623
[Hyperdrive](/hyperdrive/) is a service for connecting to your existing databases from Cloudflare Workers and Pages Functions.
618
624
619
625
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.
620
626
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**.
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
+
621
636
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`:
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).
672
691
673
692
## Analytics Engine
674
693
@@ -680,10 +699,10 @@ To configure an Analytics Engine binding via the Cloudflare dashboard:
680
699
681
700
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
682
701
2. In **Account Home**, select **Workers & Pages**.
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**.
685
704
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.
687
706
7. Redeploy your project for the binding to take effect.
688
707
689
708
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:
740
759
741
760
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
742
761
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**.
745
764
5. After setting a variable name and value, select **Save**.
746
765
747
766
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:
797
816
798
817
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
799
818
2. In **Account Home**, select **Workers & Pages**.
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**.
804
824
805
825
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).
0 commit comments