Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/react/src/backend/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { registry } from "./registry";
import { serve } from "@rivetkit/nodejs";

serve(registry, {
registry.runServer({
cors: {
// IMPORTANT: Configure origins in production
origin: "*",
Expand Down
74 changes: 37 additions & 37 deletions examples/react/src/frontend/App.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
// import { useState } from "react";
// import { createClient, createRivetKit } from "@rivetkit/react";
// import type { Registry } from "../backend/registry";
//
// const client = createClient<Registry>(`http://localhost:8080/registry`);
// const { useActor } = createRivetKit(client);
//
// function App() {
// const [count, setCount] = useState(0);
// const [counterName, setCounterName] = useState("test-counter");
//
// const counter = useActor({
// name: "counter",
// key: [counterName],
// });
//
// counter.useEvent("newCount", (x: number) => setCount(x));
//
// const increment = async () => {
// await counter.connection?.increment(1);
// };
//
// return (
// <div>
// <h1>Counter: {count}</h1>
// <input
// type="text"
// value={counterName}
// onChange={(e) => setCounterName(e.target.value)}
// placeholder="Counter name"
// />
// <button onClick={increment}>Increment</button>
// </div>
// );
// }
//
// export default App;
import { useState } from "react";
import { createClient, createRivetKit } from "@rivetkit/react";
import type { registry } from "../backend/registry";

const client = createClient<typeof registry>(`http://localhost:8080/registry`);
const { useActor } = createRivetKit(client);

function App() {
const [count, setCount] = useState(0);
const [counterName, setCounterName] = useState("test-counter");

const counter = useActor({
name: "counter",
key: [counterName],
});

counter.useEvent("newCount", (x: number) => setCount(x));

const increment = async () => {
await counter.connection?.increment(1);
};

return (
<div>
<h1>Counter: {count}</h1>
<input
type="text"
value={counterName}
onChange={(e) => setCounterName(e.target.value)}
placeholder="Counter name"
/>
<button onClick={increment}>Increment</button>
</div>
);
}

export default App;
18 changes: 9 additions & 9 deletions examples/react/src/frontend/main.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// import React from "react";
// import ReactDOM from "react-dom/client";
// import App from "./App";
//
// ReactDOM.createRoot(document.getElementById("root")!).render(
// <React.StrictMode>
// <App />
// </React.StrictMode>,
// );
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
68 changes: 34 additions & 34 deletions examples/trpc/scripts/client.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
// import { createTRPCClient, httpBatchLink } from "@trpc/client";
// import type { AppRouter } from "../src/server.js";
//
// // Create tRPC client
// const client = createTRPCClient<AppRouter>({
// links: [
// httpBatchLink({
// url: "http://localhost:3001",
// }),
// ],
// });
//
// async function main() {
// console.log("🚀 tRPC Client Demo");
//
// try {
// // Increment counter
// console.log("Incrementing counter 'demo'...");
// const result = await client.increment.mutate({ name: "demo" });
// console.log("New count:", result);
//
// // Increment again
// console.log("Incrementing counter 'demo' again...");
// const result2 = await client.increment.mutate({ name: "demo" });
// console.log("New count:", result2);
//
// console.log("✅ Demo completed!");
// } catch (error) {
// console.error("❌ Error:", error);
// process.exit(1);
// }
// }
//
// main().catch(console.error);
import { createTRPCClient, httpBatchLink } from "@trpc/client";
import type { AppRouter } from "../src/server.js";

// Create tRPC client
const client = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: "http://localhost:3001",
}),
],
});

async function main() {
console.log("🚀 tRPC Client Demo");

try {
// Increment counter
console.log("Incrementing counter 'demo'...");
const result = await client.increment.mutate({ name: "demo" });
console.log("New count:", result);

// Increment again
console.log("Incrementing counter 'demo' again...");
const result2 = await client.increment.mutate({ name: "demo" });
console.log("New count:", result2);

console.log("✅ Demo completed!");
} catch (error) {
console.error("❌ Error:", error);
process.exit(1);
}
}

main().catch(console.error);
68 changes: 34 additions & 34 deletions examples/trpc/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
// import { registry } from "./registry.js";
// import { initTRPC } from "@trpc/server";
// import { createHTTPServer } from "@trpc/server/adapters/standalone";
// import { z } from "zod";
//
// // Start RivetKit
// const { client } = registry.run();
//
// // Initialize tRPC
// const t = initTRPC.create();
//
// // Create tRPC router with RivetKit integration
// const appRouter = t.router({
// // Increment a named counter
// increment: t.procedure
// .input(z.object({ name: z.string() }))
// .mutation(async ({ input }) => {
// const counter = client.counter.getOrCreate(input.name);
// const newCount = await counter.increment(1);
// return newCount;
// }),
// });
//
// // Export type for client
// export type AppRouter = typeof appRouter;
//
// // Create HTTP server
// const server = createHTTPServer({
// router: appRouter,
// });
//
// server.listen(3001);
//
// console.log("tRPC server listening at http://localhost:3001");
import { registry } from "./registry.js";
import { initTRPC } from "@trpc/server";
import { createHTTPServer } from "@trpc/server/adapters/standalone";
import { z } from "zod";

// Start RivetKit
const { client } = registry.createServer();

// Initialize tRPC
const t = initTRPC.create();

// Create tRPC router with RivetKit integration
const appRouter = t.router({
// Increment a named counter
increment: t.procedure
.input(z.object({ name: z.string() }))
.mutation(async ({ input }) => {
const counter = client.counter.getOrCreate(input.name);
const newCount = await counter.increment(1);
return newCount;
}),
});

// Export type for client
export type AppRouter = typeof appRouter;

// Create HTTP server
const server = createHTTPServer({
router: appRouter,
});

server.listen(3001);

console.log("tRPC server listening at http://localhost:3001");
Loading