Skip to content

Commit 46956f1

Browse files
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
1 parent 6dadcc2 commit 46956f1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pages/cloudflare/bindings.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,35 @@ 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 [relevant getting started section](/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 locally only simulations of the bindings will be 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 real remote resources associated to your
67+
Cloudflare account.
68+
69+
In order to use such remote bindings, since the feature is currently experimental, you'll need to explicitly
70+
enabled it in your `next.config.mjs` file:
71+
72+
```diff
73+
- initOpenNextCloudflareForDev();
74+
+ initOpenNextCloudflareForDev({
75+
+ experimental: { remoteBindings: true }
76+
+ });
77+
```
78+
79+
When the feature is turned on all you then need to do to enable remote mode for any of your bindings
80+
is to set the `experimental_remote` configuration field to `true`, exactly
81+
as documented in the [remote bindings documentation](https://developers.cloudflare.com/workers/development-testing/#remote-bindings).
82+
5483
## Other Cloudflare APIs (`cf`, `ctx`)
5584

5685
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)