Skip to content

Commit 4adf039

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 4adf039

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pages/cloudflare/bindings.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,34 @@ 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+
```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+
5482
## Other Cloudflare APIs (`cf`, `ctx`)
5583

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