Skip to content

Commit fab0bc6

Browse files
committed
Explicitly mention to use host, add optional RPC step
1 parent e91bd9f commit fab0bc6

File tree

1 file changed

+18
-2
lines changed
  • src/content/docs/workers/tutorials/live-cursors-with-nextjs-rpc-do

1 file changed

+18
-2
lines changed

src/content/docs/workers/tutorials/live-cursors-with-nextjs-rpc-do/index.mdx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,14 +795,30 @@ that will be made available to the Next.js Worker using a [`WorkerEntrypoint`](/
795795
Deploy the Worker:
796796
<PackageManagers type="run" pkg="deploy" frame="none" />
797797
798-
A URL is generated for the Worker, which will be used to update Next.js `NEXT_PUBLIC_WS_HOST` environment variable in your `.env.local` file.
798+
Copy only the host from the generated Worker URL, excluding the protocol, and set `NEXT_PUBLIC_WS_HOST` in `.env.local` to this value (e.g., `worker-unique-identifier.workers.dev`).
799799
800800
```txt title="next-rpc/.env.local" ins={2} del={1}
801801
NEXT_PUBLIC_WS_HOST=localhost:8787
802-
NEXT_PUBLIC_WS_HOST=<DEPLOYED-WORKER-HOST>
802+
NEXT_PUBLIC_WS_HOST=worker-unique-identifier.workers.dev
803803
```
804804
805805
2. Change into your root directory and deploy your Next.js app:
806+
:::note[Optional Step]
807+
Invoking Durable Object RPC methods between separate workers are fully supported in Cloudflare deployments. You can opt to use them instead of Service Bindings RPC:
808+
```ts title="src/app/page.tsx" ins={7-9} del={4}
809+
async function closeSessions() {
810+
"use server";
811+
const cf = await getCloudflareContext();
812+
await cf.env.RPC_SERVICE.closeSessions();
813+
814+
// Note: Not supported in `wrangler dev`
815+
const id = cf.env.CURSOR_SESSIONS.idFromName("globalRoom");
816+
const stub = cf.env.CURSOR_SESSIONS.get(id);
817+
await stub.closeSessions();
818+
}
819+
```
820+
:::
821+
806822
<PackageManagers type="run" pkg="deploy" frame="none" />
807823
808824

0 commit comments

Comments
 (0)