Skip to content

Commit 3087334

Browse files
Explain how to do local dev when you have DOs with a framework (#21198)
* mroe details on DO local dev issue * some clarifications * jsonc * move to get platform proxy section * Update api.mdx Co-authored-by: Carmen Popoviciu <[email protected]> * Update api.mdx Co-authored-by: Carmen Popoviciu <[email protected]> * Update api.mdx Co-authored-by: Carmen Popoviciu <[email protected]> * remove anchor link * Update src/content/docs/workers/wrangler/api.mdx Co-authored-by: Carmen Popoviciu <[email protected]> * revert any changes to DO page --------- Co-authored-by: Carmen Popoviciu <[email protected]>
1 parent 40e9000 commit 3087334

File tree

1 file changed

+62
-22
lines changed
  • src/content/docs/workers/wrangler

1 file changed

+62
-22
lines changed

src/content/docs/workers/wrangler/api.mdx

+62-22
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ description: A set of programmatic APIs that can be integrated with local
88
Cloudflare Workers-related workflows.
99
---
1010

11-
import { Render, TabItem, Tabs, Type, MetaInfo, WranglerConfig } from "~/components";
11+
import {
12+
Render,
13+
TabItem,
14+
Tabs,
15+
Type,
16+
MetaInfo,
17+
WranglerConfig,
18+
PackageManagers,
19+
} from "~/components";
1220

1321
Wrangler offers APIs to programmatically interact with your Cloudflare Workers.
1422

@@ -360,27 +368,6 @@ The bindings supported by `getPlatformProxy` are:
360368

361369
- [KV namespace bindings](/kv/api/)
362370

363-
- [Durable Object bindings](/durable-objects/api/)
364-
365-
- To use a Durable Object binding with `getPlatformProxy`, always [specify a `script_name`](/workers/wrangler/configuration/#durable-objects) and have the target Worker run in a separate terminal via [`wrangler dev`](/workers/wrangler/commands/#dev).
366-
367-
For example, you might have the following file read by `getPlatformProxy`.
368-
369-
<WranglerConfig>
370-
371-
```toml
372-
[[durable_objects.bindings]]
373-
name = "MyDurableObject"
374-
class_name = "MyDurableObject"
375-
script_name = "my-worker"
376-
```
377-
378-
</WranglerConfig>
379-
380-
In order for this binding to be successfully proxied by `getPlatformProxy`, a worker named `my-worker`
381-
with a Durable Object declaration using the same `class_name` of `"MyDurableObject"` must be run
382-
separately via `wrangler dev`.
383-
384371
- [R2 bucket bindings](/r2/api/workers/workers-api-reference/)
385372

386373
- [Queue bindings](/queues/configuration/javascript-apis/)
@@ -399,3 +386,56 @@ The bindings supported by `getPlatformProxy` are:
399386
- [Workers AI bindings](/workers-ai/get-started/workers-wrangler/#2-connect-your-worker-to-workers-ai)
400387

401388
<Render file="ai-local-usage-charges" product="workers" />
389+
390+
- [Durable Object bindings](/durable-objects/api/)
391+
392+
- To use a Durable Object binding with `getPlatformProxy`, always specify a [`script_name`](/workers/wrangler/configuration/#durable-objects).
393+
394+
For example, you might have the following binding in a Wrangler configuration file read by `getPlatformProxy`.
395+
396+
<WranglerConfig>
397+
398+
```toml
399+
[[durable_objects.bindings]]
400+
name = "MyDurableObject"
401+
class_name = "MyDurableObject"
402+
script_name = "external-do-worker"
403+
```
404+
405+
</WranglerConfig>
406+
407+
You will need to declare your Durable Object `"MyDurableObject"` in another Worker, called `external-do-worker` in this example.
408+
409+
```ts title="./external-do-worker/src/index.ts"
410+
export class MyDurableObject extends DurableObject {
411+
// Your DO code goes here
412+
}
413+
414+
export default {
415+
fetch() {
416+
// Doesn't have to do anything, but a DO cannot be the default export
417+
return new Response("Hello, world!");
418+
},
419+
};
420+
```
421+
That Worker also needs a Wrangler configuration file that looks like this:
422+
423+
<WranglerConfig>
424+
```json
425+
{
426+
"name": "external-do-worker",
427+
"main": "src/index.ts",
428+
"compatibility_date": "XXXX-XX-XX"
429+
}
430+
```
431+
</WranglerConfig>
432+
433+
If you are not using RPC with your Durable Object, you can run a separate Wrangler dev session alongside your framework development server.
434+
435+
Otherwise, you can build your application and run both Workers in the same Wrangler dev session.
436+
437+
If you are using Pages run:
438+
<PackageManagers type="exec" pkg="wrangler" args="pages dev -c path/to/pages/wrangler.jsonc -c path/to/external-do-worker/wrangler.jsonc" />
439+
440+
If you are using Workers with Assets run:
441+
<PackageManagers type="exec" pkg="wrangler" args="dev -c path/to/workers-assets/wrangler.jsonc -c path/to/external-do-worker/wrangler.jsonc" />

0 commit comments

Comments
 (0)