Skip to content

Commit e05a674

Browse files
committed
move to get platform proxy section
1 parent 70984bc commit e05a674

File tree

2 files changed

+63
-99
lines changed

2 files changed

+63
-99
lines changed

src/content/docs/durable-objects/platform/known-issues.mdx

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ pcx_content_type: concept
33
title: Known issues
44
---
55

6-
import {
7-
GlossaryTooltip,
8-
Steps,
9-
WranglerConfig,
10-
PackageManagers,
11-
} from "~/components";
6+
import { GlossaryTooltip, Steps } from "~/components";
127

138
Durable Objects is generally available. However, there are some known issues.
149

@@ -41,74 +36,3 @@ The Workers editor in the [Cloudflare dashboard](https://dash.cloudflare.com/) a
4136
Currently, when developing locally (using `npx wrangler dev`), Durable Object [alarm methods](/durable-objects/api/alarms) may fail after a hot reload (if you edit the code while the code is running locally).
4237

4338
To avoid this issue, when using Durable Object alarms, close and restart your `wrangler dev` command after editing your code.
44-
45-
## Local development with web frameworks
46-
47-
When developing a Pages or Workers Assets application, you may have to define your Durable Object in a separate Worker in order to develop locally.
48-
This only applies to frameworks that use a development server that runs in Node.js. We are working to improve this experience - for example, frameworks that use the Cloudflare Vite plugin do not have this issue.
49-
50-
For now, you can set up your project like this to enable local development. In this example, we assume you have a pre-existing Worker that you want to add a DO binding to.
51-
52-
<Steps>
53-
1. Create a second Worker with your Durable Object code.
54-
55-
```ts title="src/index.ts"
56-
export class MyDurableObject extends DurableObject {
57-
// Your DO code goes here
58-
}
59-
60-
export default {
61-
fetch() {
62-
// Doesn't have to do anything, but a DO cannot be the default export
63-
return new Response("Hello, world!");
64-
},
65-
};
66-
```
67-
68-
2. Create a **new** Wrangler config file for this Worker.
69-
70-
<WranglerConfig>
71-
```json
72-
{
73-
"name": "external-do-worker",
74-
"main": "src/index.ts",
75-
"compatibility_date": "XXXX-XX-XX"
76-
}
77-
```
78-
</WranglerConfig>
79-
80-
3. Update your **original** Durable Object bindings in your pre-existing Wrangler config file to include the `script_name` field. This should be the same as the `name` field in the new Worker's config.
81-
82-
<WranglerConfig>
83-
84-
```json
85-
{
86-
...
87-
"durable_objects": {
88-
"bindings": [
89-
{
90-
"name": "BINDING",
91-
"class_name": "MyDurableObject",
92-
"script_name": "external-do-worker",
93-
},
94-
],
95-
},
96-
...
97-
},
98-
```
99-
100-
</WranglerConfig>
101-
102-
4. Develop locally
103-
104-
If you are not using RPC with your Durable Object, you can run a separate Wrangler dev session alongside your framework development server.
105-
106-
Otherwise, you can build your application and run both Workers in the same Wrangler dev session.
107-
108-
If you are using Pages:
109-
<PackageManagers type="exec" pkg="wrangler" args="pages dev -c path/to/pages/wrangler.jsonc -c path/to/external-do-worker/wrangler.jsonc" />
110-
111-
If you are using Workers with Assets:
112-
<PackageManagers type="exec" pkg="wrangler" args="dev -c path/to/workers-assets/wrangler.jsonc -c path/to/external-do-worker/wrangler.jsonc" />
113-
114-
</Steps>

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

Lines changed: 62 additions & 22 deletions
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+
- <a name="durable-objects"></a>[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 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 config 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:
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:
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)