Skip to content

Commit f8dbb7e

Browse files
add a section about local access in the Cloudflare bindings documentation (#167)
Co-authored-by: Victor Berchet <[email protected]>
1 parent 6dadcc2 commit f8dbb7e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pages/cloudflare/bindings.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,40 @@ This will generate a `d.ts` file and save it to `worker-configuration.d.ts`.
5151

5252
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.
5353

54+
## Local access to bindings
55+
56+
As presented in the [getting started](/cloudflare/get-started#12-develop-locally) your application can be both developed (`next dev`) and
57+
previewed (`opennextjs-cloudflare preview`) locally, in both cases bindings will be accessible from your application's code.
58+
59+
Such bindings are by default local simulation that mimic the behavior of the actual Cloudflare resources.
60+
61+
### Remote bindings
62+
63+
As mentioned above, by default local emulations of the bindings are used.
64+
65+
However [remote bindings](https://developers.cloudflare.com/workers/development-testing/#remote-bindings) can also be
66+
used, allowing your application code, while still running locally, to connect to remote resources associated to your
67+
Cloudflare account.
68+
69+
Remote bindings are currently experimental and can be enabled it in your `next.config.ts` file:
70+
71+
```diff
72+
- initOpenNextCloudflareForDev();
73+
+ initOpenNextCloudflareForDev({
74+
+ experimental: { remoteBindings: true }
75+
+ });
76+
```
77+
78+
When the feature is turned on all you then need to do to enable remote mode for any of your bindings
79+
is to set the `experimental_remote` configuration field to `true`, exactly
80+
as documented in the [remote bindings documentation](https://developers.cloudflare.com/workers/development-testing/#remote-bindings).
81+
82+
<Callout>
83+
Note that remote bindings will also be used during build, this can be very useful for example when using
84+
features such [ISR](https://nextjs.org/docs/app/guides/incremental-static-regeneration) so that read
85+
production data can be used for the site's static generation
86+
</Callout>
87+
5488
## Other Cloudflare APIs (`cf`, `ctx`)
5589

5690
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):

0 commit comments

Comments
 (0)