From 46956f163bbc4d8aea79348de139f8bc777eea17 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Thu, 26 Jun 2025 09:47:07 +0100 Subject: [PATCH 1/5] add a section about local access in the Cloudflare bindings documentation add a section to the Cloudflare bindings documentation, documenting that: - bindings can be used both for dev and preview (this is already stated in the get started guide but I believe that it should also be included in the bindings documentation as well) - add information on remote bindings and how people can used them --- pages/cloudflare/bindings.mdx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pages/cloudflare/bindings.mdx b/pages/cloudflare/bindings.mdx index f450cb0..bc0778b 100644 --- a/pages/cloudflare/bindings.mdx +++ b/pages/cloudflare/bindings.mdx @@ -51,6 +51,35 @@ This will generate a `d.ts` file and save it to `worker-configuration.d.ts`. To ensure that your types are always up-to-date, make sure to run `wrangler types --env-interface CloudflareEnv` after any changes to your config file. +## Local access to bindings + +As presented in the [relevant getting started section](/cloudflare/get-started#12-develop-locally) your application can be both developed (`next dev`) and +previewed (`opennextjs-cloudflare preview`) locally, in both cases bindings will be accessible from your application's code. + +Such bindings are by default local simulation that mimic the behavior of the actual Cloudflare resources. + +### Remote bindings + +As mentioned above, by default locally only simulations of the bindings will be used. + +However [remote bindings](https://developers.cloudflare.com/workers/development-testing/#remote-bindings) can also be +used, allowing your application code, while still running locally, to connect to real remote resources associated to your +Cloudflare account. + +In order to use such remote bindings, since the feature is currently experimental, you'll need to explicitly +enabled it in your `next.config.mjs` file: + +```diff +- initOpenNextCloudflareForDev(); ++ initOpenNextCloudflareForDev({ ++ experimental: { remoteBindings: true } ++ }); +``` + +When the feature is turned on all you then need to do to enable remote mode for any of your bindings +is to set the `experimental_remote` configuration field to `true`, exactly +as documented in the [remote bindings documentation](https://developers.cloudflare.com/workers/development-testing/#remote-bindings). + ## Other Cloudflare APIs (`cf`, `ctx`) You can access context about the incoming request from the [`cf` object](https://developers.cloudflare.com/workers/runtime-apis/request/#the-cf-property-requestinitcfproperties), as well as lifecycle methods from the [`ctx` object](https://developers.cloudflare.com/workers/runtime-apis/context) from the return value of [`getCloudflareContext()`](https://github.com/opennextjs/opennextjs-cloudflare/blob/main/packages/cloudflare/src/api/cloudflare-context.ts): From be0dece45a5849075e1b282197da995622e798f0 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Thu, 26 Jun 2025 10:11:46 +0100 Subject: [PATCH 2/5] Update pages/cloudflare/bindings.mdx Co-authored-by: Victor Berchet --- pages/cloudflare/bindings.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/cloudflare/bindings.mdx b/pages/cloudflare/bindings.mdx index bc0778b..52f2d07 100644 --- a/pages/cloudflare/bindings.mdx +++ b/pages/cloudflare/bindings.mdx @@ -53,7 +53,7 @@ To ensure that your types are always up-to-date, make sure to run `wrangler type ## Local access to bindings -As presented in the [relevant getting started section](/cloudflare/get-started#12-develop-locally) your application can be both developed (`next dev`) and +As presented in the [getting started](/cloudflare/get-started#12-develop-locally) your application can be both developed (`next dev`) and previewed (`opennextjs-cloudflare preview`) locally, in both cases bindings will be accessible from your application's code. Such bindings are by default local simulation that mimic the behavior of the actual Cloudflare resources. From bf79523cafd838e51c3c5bbb079193bdf9fa391c Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Thu, 26 Jun 2025 10:14:09 +0100 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: Victor Berchet --- pages/cloudflare/bindings.mdx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pages/cloudflare/bindings.mdx b/pages/cloudflare/bindings.mdx index 52f2d07..4e677b4 100644 --- a/pages/cloudflare/bindings.mdx +++ b/pages/cloudflare/bindings.mdx @@ -60,14 +60,13 @@ Such bindings are by default local simulation that mimic the behavior of the act ### Remote bindings -As mentioned above, by default locally only simulations of the bindings will be used. +As mentioned above, by default local emulations of the bindings are used. However [remote bindings](https://developers.cloudflare.com/workers/development-testing/#remote-bindings) can also be -used, allowing your application code, while still running locally, to connect to real remote resources associated to your +used, allowing your application code, while still running locally, to connect to remote resources associated to your Cloudflare account. -In order to use such remote bindings, since the feature is currently experimental, you'll need to explicitly -enabled it in your `next.config.mjs` file: +Remote bindings are currently experimental and can be enabled enabled it in your `next.config.ts` file: ```diff - initOpenNextCloudflareForDev(); From 3c3fc27a419d6fe775f6b288f05ed9cb1f44185b Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Thu, 26 Jun 2025 11:15:24 +0100 Subject: [PATCH 4/5] add callout with build example --- pages/cloudflare/bindings.mdx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pages/cloudflare/bindings.mdx b/pages/cloudflare/bindings.mdx index 4e677b4..c30665f 100644 --- a/pages/cloudflare/bindings.mdx +++ b/pages/cloudflare/bindings.mdx @@ -79,6 +79,12 @@ When the feature is turned on all you then need to do to enable remote mode for is to set the `experimental_remote` configuration field to `true`, exactly as documented in the [remote bindings documentation](https://developers.cloudflare.com/workers/development-testing/#remote-bindings). + + Note that remote bindings will also be used during build, this can be very useful for example when using + features such [ISR](https://nextjs.org/docs/app/guides/incremental-static-regeneration) so that read + production data can be used for the site's static generation + + ## Other Cloudflare APIs (`cf`, `ctx`) You can access context about the incoming request from the [`cf` object](https://developers.cloudflare.com/workers/runtime-apis/request/#the-cf-property-requestinitcfproperties), as well as lifecycle methods from the [`ctx` object](https://developers.cloudflare.com/workers/runtime-apis/context) from the return value of [`getCloudflareContext()`](https://github.com/opennextjs/opennextjs-cloudflare/blob/main/packages/cloudflare/src/api/cloudflare-context.ts): From 74a3c46deab2e54002d0dcf999d86cd2efe99dae Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Thu, 26 Jun 2025 11:34:27 +0100 Subject: [PATCH 5/5] remove double enabled --- pages/cloudflare/bindings.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/cloudflare/bindings.mdx b/pages/cloudflare/bindings.mdx index c30665f..e86e8a6 100644 --- a/pages/cloudflare/bindings.mdx +++ b/pages/cloudflare/bindings.mdx @@ -66,7 +66,7 @@ However [remote bindings](https://developers.cloudflare.com/workers/development- used, allowing your application code, while still running locally, to connect to remote resources associated to your Cloudflare account. -Remote bindings are currently experimental and can be enabled enabled it in your `next.config.ts` file: +Remote bindings are currently experimental and can be enabled it in your `next.config.ts` file: ```diff - initOpenNextCloudflareForDev();