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
Copy file name to clipboardExpand all lines: src/content/docs/workers/development-testing/index.mdx
+49-91Lines changed: 49 additions & 91 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,9 +67,9 @@ During local development, your Worker code interacts with these bindings using t
67
67
- By default, bindings connect to **local resource simulations** (except for [AI bindings](/workers-ai/configuration/bindings/), as AI models always run remotely).
68
68
- You can override this default behavior and **connect to the remote resource**, on a per-binding basis. This lets you connect to real, production resources while still running your Worker code locally.
69
69
70
-
## Remote bindings <InlineBadgepreset="beta"/>
70
+
## Remote bindings
71
71
72
-
**Remote bindings** are bindings that are configured to connect to the deployed, remote resource during local development _instead_ of the locally simulated resource. You can configure remote bindings by setting `experimental_remote: true` in the binding definition.
72
+
**Remote bindings** are bindings that are configured to connect to the deployed, remote resource during local development _instead_ of the locally simulated resource. Remote bindings are supported by [**Wrangler**](/workers/wrangler/), the [**Cloudflare Vite plugin**](/workers/vite-plugin/), and the `@cloudflare/vitest-pool-workers` package. You can configure remote bindings by setting `remote: true` in the binding definition.
73
73
74
74
### Example configuration
75
75
@@ -84,58 +84,15 @@ During local development, your Worker code interacts with these bindings using t
84
84
{
85
85
"bucket_name":"screenshots-bucket",
86
86
"binding":"screenshots_bucket",
87
-
"experimental_remote":true,
87
+
"remote":true,
88
88
},
89
89
],
90
90
}
91
91
```
92
92
93
93
</WranglerConfig>
94
94
95
-
When remote bindings are configured, your Worker still **executes locally**, only the underlying resources your bindings connect to change. For all bindings marked with `experimental_remote: true`, Miniflare will route its operations (such as `env.MY_KV.put()`) to the deployed resource. All other bindings not explicitly configured with `experimental_remote: true` continue to use their default local simulations.
96
-
97
-
### Using Wrangler with remote bindings
98
-
99
-
If you're using [Wrangler](/workers/wrangler/) for local development and have remote bindings configured, you'll need to use the following experimental command:
If you're using Vite via [the Cloudflare Vite plugin](/workers/vite-plugin/), you'll need to add support for remote bindings in your Vite configuration (`vite.config.ts`):
When remote bindings are configured, your Worker still **executes locally**, only the underlying resources your bindings connect to change. For all bindings marked with `remote: true`, Miniflare will route its operations (such as `env.MY_KV.put()`) to the deployed resource. All other bindings not explicitly configured with `remote: true` continue to use their default local simulations.
139
96
140
97
### Targeting preview resources
141
98
@@ -145,7 +102,7 @@ To protect production data, you can create and specify preview resources in your
145
102
-[Preview buckets for R2 storage](/workers/wrangler/configuration/#r2-buckets): `preview_bucket_name`.
146
103
-[Preview database IDs for D1](/workers/wrangler/configuration/#d1-databases): `preview_database_id`
147
104
148
-
If preview configuration is present for a binding, setting `experimental_remote: true` will ensure that remote bindings connect to that designated remote preview resource.
105
+
If preview configuration is present for a binding, setting `remote: true` will ensure that remote bindings connect to that designated remote preview resource.
149
106
150
107
**For example:**
151
108
@@ -161,15 +118,15 @@ If preview configuration is present for a binding, setting `experimental_remote:
Running `wrangler dev --x-remote-bindings` with the above configuration means that:
129
+
Running `wrangler dev` with the above configuration means that:
173
130
174
131
- Your Worker code runs locally
175
132
- All calls made to `env.screenshots_bucket` will use the `preview-screenshots-bucket` resource, rather than the production `screenshots-bucket`.
@@ -178,7 +135,7 @@ Running `wrangler dev --x-remote-bindings` with the above configuration means th
178
135
179
136
We recommend configuring specific bindings to connect to their remote counterparts. These services often rely on Cloudflare's network infrastructure or have complex backends that are not fully simulated locally.
180
137
181
-
The following bindings are recommended to have `experimental_remote: true` in your Wrangler configuration:
138
+
The following bindings are recommended to have `remote: true` in your Wrangler configuration:
@@ -256,22 +213,22 @@ To connect to a high-fidelity version of the Images API, and verify that all tra
256
213
{
257
214
"images": {
258
215
"binding": "IMAGES" ,
259
-
"experimental_remote":true
216
+
"remote": true
260
217
}
261
218
}
262
-
```
219
+
````
263
220
264
221
</WranglerConfig>
265
222
266
223
:::note
267
-
If `experimental_remote: true` is not specified for Browser Rendering, Vectorize, mTLS, or Images, Cloudflare **will issue a warning**. This prompts you to consider enabling it for a more production-like testing experience.
224
+
If `remote:true` is not specified for Browser Rendering, Vectorize, mTLS, or Images, Cloudflare **will issue a warning**. This prompts you to consider enabling it for a more production-like testing experience.
268
225
269
-
If a Workers AI binding has `experimental_remote` set to `false`, Cloudflare will **produce an error**. If the property is omitted, Cloudflare will connect to the remote resource and issue a warning to add the property to configuration.
226
+
If a Workers AI binding has `remote` set to `false`, Cloudflare will **produce an error**. If the property is omitted, Cloudflare will connect to the remote resource and issue a warning to add the property to configuration.
Workers for Platforms users can configure `experimental_remote: true` in dispatch namespace binding definitions:
231
+
Workers for Platforms users can configure `remote:true` in dispatch namespace binding definitions:
275
232
276
233
<WranglerConfig>
277
234
```jsonc title="wrangler.jsonc"
@@ -280,7 +237,7 @@ Workers for Platforms users can configure `experimental_remote: true` in dispatc
280
237
{
281
238
"binding":"DISPATCH_NAMESPACE",
282
239
"namespace":"testing",
283
-
"experimental_remote":true
240
+
"remote":true
284
241
}
285
242
]
286
243
}
@@ -291,9 +248,9 @@ This allows you to run your [dynamic dispatch Worker](/cloudflare-for-platforms/
291
248
292
249
### Unsupported remote bindings
293
250
294
-
Certain bindings are not supported for remote connections during local development (`experimental_remote: true`). These will always use local simulations or local values.
251
+
Certain bindings are not supported for remote connections (i.e. with `remote: true`) during local development. These will always use local simulations or local values.
295
252
296
-
If `experimental_remote: true` is specified in Wrangler configuration for any of the following unsupported binding types, Cloudflare **will issue an error**. See [all supported and unsupported bindings for remote bindings](/workers/development-testing/bindings-per-env/).
253
+
If `remote: true` is specified in Wrangler configuration for any of the following unsupported binding types, Cloudflare **will issue an error**. See [all supported and unsupported bindings for remote bindings](/workers/development-testing/bindings-per-env/).
297
254
298
255
-[**Durable Objects**](/workers/wrangler/configuration/#durable-objects): Enabling remote connections for Durable Objects may be supported in the future, but currently will always run locally. However, using Durable Objects in combination with remote bindings is possible. Refer to [Using remote resources with Durable Objects and Workflows](#using-remote-resources-with-durable-objects-and-workflows) below.
299
256
@@ -325,13 +282,12 @@ There are two recommended patterns for this:
325
282
326
283
-**Local Durable Objects/Workflows with remote bindings:**
327
284
328
-
When you enable remote bindings in your [Wrangler configuration](/workers/wrangler/configuration), your locally running Durable Objects and Workflows can access remote resources. This allows such bindings, although run locally, to interact with remote resources during local development.
285
+
When you enable remote bindings in your [Wrangler configuration](/workers/wrangler/configuration), your locally running Durable Objects and Workflows can access remote resources. This allows such bindings, although run locally, to interact with remote resources during local development.
329
286
330
287
-**Accessing remote Durable Objects/Workflows via service bindings:**
331
288
332
-
To interact with remote Durable Object or Workflow instances, deploy a Worker that defines those. Then, in your local Worker, configure a remote [service binding](/workers/runtime-apis/bindings/service-bindings/) pointing to the deployed Worker.
333
-
Your local Worker will be then able to interact with the remote deployed Worker, which in turn can communicate with the remote Durable Objects/Workflows. Using this method, you can create a communication channel via the remote service binding, effectively using the deployed Worker as a proxy interface to the remote bindings during local development.
334
-
289
+
To interact with remote Durable Object or Workflow instances, deploy a Worker that defines those. Then, in your local Worker, configure a remote [service binding](/workers/runtime-apis/bindings/service-bindings/) pointing to the deployed Worker.
290
+
Your local Worker will be then able to interact with the remote deployed Worker, which in turn can communicate with the remote Durable Objects/Workflows. Using this method, you can create a communication channel via the remote service binding, effectively using the deployed Worker as a proxy interface to the remote bindings during local development.
335
291
336
292
### Important Considerations
337
293
@@ -347,11 +303,11 @@ Wrangler provides programmatic utilities to help tooling authors support remote
347
303
348
304
**Key APIs include:**
349
305
350
-
-[`experimental_startRemoteProxySession`](#experimental_startRemoteProxySession): Starts a proxy session that allows interaction with remote bindings.
306
+
-[`startRemoteProxySession`](#startRemoteProxySession): Starts a proxy session that allows interaction with remote bindings.
351
307
-[`unstable_convertConfigBindingsToStartWorkerBindings`](#unstable_convertconfigbindingstostartworkerbindings): Utility for converting binding definitions.
352
308
-[`experimental_maybeStartOrUpdateProxySession`](#experimental_maybestartorupdatemixedmodesession): Convenience function to easily start or update a proxy session.
353
309
354
-
#### `experimental_startRemoteProxySession`
310
+
#### `startRemoteProxySession`
355
311
356
312
This function starts a proxy session for a given set of bindings. It accepts options to control session behavior, including an `auth` option with your Cloudflare account ID and API token for remote binding access.
The `unstable_readConfig` utility returns an `Unstable_Config` object which includes the definition of the bindings included in the configuration file. These bindings definitions
368
-
are however not directly compatible with `experimental_startRemoteProxySession`. It can be quite convenient to however read the binding declarations with `unstable_readConfig` and then
369
-
pass them to `experimental_startRemoteProxySession`, so for this wrangler exposes `unstable_convertConfigBindingsToStartWorkerBindings` which is a simple utility to convert
370
-
the bindings in an `Unstable_Config` object into a structure that can be passed to `experimental_startRemoteProxySession`.
324
+
are however not directly compatible with `startRemoteProxySession`. It can be quite convenient to however read the binding declarations with `unstable_readConfig` and then
325
+
pass them to `startRemoteProxySession`, so for this wrangler exposes `unstable_convertConfigBindingsToStartWorkerBindings` which is a simple utility to convert
326
+
the bindings in an `Unstable_Config` object into a structure that can be passed to `startRemoteProxySession`.
371
327
372
328
:::note
373
-
This type conversion is temporary. In the future, the types will be unified so you can pass the config object directly to `experimental_startRemoteProxySession`.
329
+
This type conversion is temporary. In the future, the types will be unified so you can pass the config object directly to `startRemoteProxySession`.
This wrapper simplifies proxy session management. It takes:
379
335
@@ -391,32 +347,36 @@ The function:
391
347
- If there are no remote bindings to be used (nor a pre-existing proxy session) it returns null, signaling that no proxy session is needed.
392
348
- If the details of an existing proxy session have been provided it updates the proxy session accordingly.
393
349
- Otherwise if starts a new proxy session.
394
-
- Returns the proxy session details (that can later be passed as the second argument to `experimental_maybeStartOrUpdateRemoteProxySession`).
350
+
- Returns the proxy session details (that can later be passed as the second argument to `maybeStartOrUpdateRemoteProxySession`).
395
351
396
352
#### Example
397
353
398
-
Here's a basic example of using Miniflare with `experimental_maybeStartOrUpdateRemoteProxySession` to provide a local dev session with remote bindings. This example uses a single hardcoded KV binding.
354
+
Here's a basic example of using Miniflare with `maybeStartOrUpdateRemoteProxySession` to provide a local dev session with remote bindings. This example uses a single hardcoded KV binding.
@@ -441,10 +401,9 @@ async function startOrUpdateDevSession() {
441
401
442
402
// ... once the dev session is no longer needed run
443
403
// `remoteProxySessionDetails?.session.dispose()`
444
-
445
404
```
446
-
</TypeScriptExample>
447
405
406
+
</TypeScriptExample>
448
407
449
408
## `wrangler dev --remote` (Legacy)
450
409
@@ -468,4 +427,3 @@ When using remote development, all bindings automatically connect to their remot
468
427
### Limitations
469
428
470
429
- When you run a remote development session using the `--remote` flag, a limit of 50 [routes](/workers/configuration/routing/routes/) per zone is enforced. Learn more in[ Workers platform limits](/workers/platform/limits/#number-of-routes-per-zone-when-using-wrangler-dev---remote).
0 commit comments