Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit e7a3580

Browse files
committed
chore: add rivet as a default driver
1 parent 06f601c commit e7a3580

File tree

96 files changed

+1685
-2281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1685
-2281
lines changed

docs/workers/quickstart.mdx

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,18 @@ export const registry = setup({
4242
import { registry } from "./registry";
4343
import { Hono } from "hono";
4444
import { serve } from "@hono/node-server";
45+
import { createNodeWebSocket } from '@hono/node-ws'
46+
47+
// Setup server
48+
const app = new Hono();
4549

4650
// Start RivetKit
4751
//
4852
// State is stored in memory, this can be configured later
49-
const { client, hono } = registry.run();
50-
51-
// Setup server
52-
const app = new Hono();
53+
const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app }) // TODO: do this before app
54+
const { client, hono } = registry.run({
55+
getUpgradeWebSocket: () => upgradeWebSocket,
56+
});
5357

5458
// Expose RivetKit to the frontend (optional)
5559
app.route("/registry", hono);
@@ -67,6 +71,7 @@ app.post("/increment/:name", async (c) => {
6771
serve({ fetch: app.fetch, port: 8080 }, (x) =>
6872
console.log("Listening at http://localhost:8080"),
6973
);
74+
injectWebSocket(server)
7075
```
7176

7277
```ts Express.js
@@ -77,6 +82,37 @@ TODO
7782
TODO
7883
```
7984

85+
```ts Hono
86+
import { registry } from "./registry";
87+
import { Hono } from "hono";
88+
89+
// Start RivetKit
90+
//
91+
// State is stored in memory, this can be configured later
92+
const { client, serve } = registry.server();
93+
94+
// Setup server
95+
const app = new Hono();
96+
97+
// Example endpoint
98+
app.post("/increment/:name", async (c) => {
99+
const name = c.req.param("name");
100+
101+
// Communicate with actor
102+
const counter = client.counter.getOrCreate(name);
103+
const newCount = await counter.increment(1);
104+
105+
return c.text(`New Count: ${newCount}`);
106+
});
107+
108+
// Start server
109+
serve(app);
110+
```
111+
112+
TODO: How to serve without registry helper
113+
114+
TODO: Why we need to use our own custom serve fn
115+
80116
</CodeGroup>
81117

82118
<Info>

examples/better-auth/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
},
2626
"dependencies": {
2727
"@hono/node-server": "^1.14.4",
28-
"@rivetkit/memory": "workspace:0.9.0-rc.1",
2928
"@rivetkit/react": "workspace:0.9.0-rc.1",
3029
"better-auth": "^1.0.1",
3130
"hono": "^4.7.0",
Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,54 @@
1-
import { registry } from "./registry";
2-
import { auth } from "./auth";
3-
import { Hono } from "hono";
4-
import { serve } from "@hono/node-server";
5-
import { createMemoryDriver } from "@rivetkit/memory";
6-
7-
// Setup router
8-
const app = new Hono();
9-
10-
// Start RivetKit
11-
const { client, hono } = registry.run({
12-
driver: createMemoryDriver(),
13-
cors: {
14-
// IMPORTANT: Configure origins in production
15-
origin: "*",
16-
},
17-
});
18-
19-
// Mount Better Auth routes
20-
app.on(["GET", "POST"], "/api/auth/**", (c) => auth.handler(c.req.raw));
21-
22-
// Expose RivetKit to the frontend
23-
app.route("/registry", hono);
24-
25-
// Example HTTP endpoint to join chat room
26-
app.post("/api/join-room/:roomId", async (c) => {
27-
const roomId = c.req.param("roomId");
28-
29-
// Verify authentication
30-
const authResult = await auth.api.getSession({
31-
headers: c.req.header(),
32-
});
33-
34-
if (!authResult?.session || !authResult?.user) {
35-
return c.json({ error: "Unauthorized" }, 401);
36-
}
37-
38-
try {
39-
const room = client.chatRoom.getOrCreate(roomId);
40-
const messages = await room.getMessages();
41-
42-
return c.json({
43-
success: true,
44-
roomId,
45-
messages,
46-
user: authResult.user
47-
});
48-
} catch (error) {
49-
return c.json({ error: "Failed to join room" }, 500);
50-
}
51-
});
52-
53-
serve({ fetch: app.fetch, port: 6420 }, () =>
54-
console.log("Listening at http://localhost:6420"),
55-
);
1+
// import { registry } from "./registry";
2+
// import { auth } from "./auth";
3+
// import { Hono } from "hono";
4+
// import { serve } from "@hono/node-server";
5+
//
6+
// // Setup router
7+
// const app = new Hono();
8+
//
9+
// // Start RivetKit
10+
// const { client, hono } = registry.run({
11+
// driver: createMemoryDriver(),
12+
// cors: {
13+
// // IMPORTANT: Configure origins in production
14+
// origin: "*",
15+
// },
16+
// });
17+
//
18+
// // Mount Better Auth routes
19+
// app.on(["GET", "POST"], "/api/auth/**", (c) => auth.handler(c.req.raw));
20+
//
21+
// // Expose RivetKit to the frontend
22+
// app.route("/registry", hono);
23+
//
24+
// // Example HTTP endpoint to join chat room
25+
// app.post("/api/join-room/:roomId", async (c) => {
26+
// const roomId = c.req.param("roomId");
27+
//
28+
// // Verify authentication
29+
// const authResult = await auth.api.getSession({
30+
// headers: c.req.header(),
31+
// });
32+
//
33+
// if (!authResult?.session || !authResult?.user) {
34+
// return c.json({ error: "Unauthorized" }, 401);
35+
// }
36+
//
37+
// try {
38+
// const room = client.chatRoom.getOrCreate(roomId);
39+
// const messages = await room.getMessages();
40+
//
41+
// return c.json({
42+
// success: true,
43+
// roomId,
44+
// messages,
45+
// user: authResult.user
46+
// });
47+
// } catch (error) {
48+
// return c.json({ error: "Failed to join room" }, 500);
49+
// }
50+
// });
51+
//
52+
// serve({ fetch: app.fetch, port: 6420 }, () =>
53+
// console.log("Listening at http://localhost:6420"),
54+
// );

examples/chat-room/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
"typescript": "^5.5.2",
1818
"vitest": "^3.1.1"
1919
},
20-
"dependencies": {
21-
"@rivetkit/nodejs": "workspace:*"
22-
},
2320
"example": {
2421
"platforms": [
2522
"*"

examples/chat-room/src/server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { serve } from "@rivetkit/nodejs";
2-
import { registry } from "./workers/registry";
3-
4-
serve(registry);
1+
// import { serve } from "@rivetkit/nodejs";
2+
// import { registry } from "./workers/registry";
3+
//
4+
// serve(registry);

examples/counter/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
"typescript": "^5.7.3",
1616
"vitest": "^3.1.1"
1717
},
18-
"dependencies": {
19-
"@rivetkit/nodejs": "workspace:*"
20-
},
2118
"example": {
2219
"platforms": [
2320
"*"

examples/counter/src/server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { serve } from "@rivetkit/nodejs";
2-
import { registry } from "./workers/registry";
3-
4-
serve(registry);
1+
// import { serve } from "@rivetkit/nodejs";
2+
// import { registry } from "./workers/registry";
3+
//
4+
// serve(registry);

examples/elysia/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"typescript": "^5.5.2"
1414
},
1515
"dependencies": {
16-
"@rivetkit/memory": "workspace:0.9.0-rc.1",
1716
"@rivetkit/react": "workspace:0.9.0-rc.1",
1817
"elysia": "^1.3.5",
1918
"react": "^18.2.0",

examples/elysia/src/server.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import { registry } from "./registry";
2-
import { Elysia } from "elysia";
3-
import { createMemoryDriver } from "@rivetkit/memory";
4-
5-
// Start RivetKit
6-
const { client, handler } = registry.run({
7-
driver: createMemoryDriver(),
8-
});
9-
10-
// Setup router
11-
const app = new Elysia()
12-
// Expose RivetKit to the frontend (optional)
13-
.mount("/registry", handler)
14-
// Example HTTP endpoint
15-
.post("/increment/:name", async ({ params }) => {
16-
const name = params.name;
17-
18-
const counter = client.counter.getOrCreate(name);
19-
const newCount = await counter.increment(1);
20-
21-
return `New Count: ${newCount}`;
22-
})
23-
.listen(6420);
24-
25-
console.log("Listening at http://localhost:6420");
1+
// import { registry } from "./registry";
2+
// import { Elysia } from "elysia";
3+
// import { createMemoryDriver } from "@rivetkit/memory";
4+
//
5+
// // Start RivetKit
6+
// const { client, handler } = registry.run({
7+
// driver: createMemoryDriver(),
8+
// });
9+
//
10+
// // Setup router
11+
// const app = new Elysia()
12+
// // Expose RivetKit to the frontend (optional)
13+
// .mount("/registry", handler)
14+
// // Example HTTP endpoint
15+
// .post("/increment/:name", async ({ params }) => {
16+
// const name = params.name;
17+
//
18+
// const counter = client.counter.getOrCreate(name);
19+
// const newCount = await counter.increment(1);
20+
//
21+
// return `New Count: ${newCount}`;
22+
// })
23+
// .listen(6420);
24+
//
25+
// console.log("Listening at http://localhost:6420");

examples/express/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"typescript": "^5.5.2"
1616
},
1717
"dependencies": {
18-
"@rivetkit/memory": "workspace:0.9.0-rc.1",
1918
"@rivetkit/react": "workspace:0.9.0-rc.1",
2019
"express": "^5.1.0",
2120
"react": "^18.2.0",

0 commit comments

Comments
 (0)