···11import { actor, setup } from "rivetkit";
2233-export const counter = actor({
44- state: { count: 0 },
55- actions: {
66- increment: (c, x: number) => {
77- c.state.count += x;
88- c.broadcast("newCount", c.state.count);
99- return c.state.count;
1010- },
1111- },
33+// Create an HTTP actor for handling requests
44+export const http = actor({
55+ // Create a raw request handler
66+ onRequest(_c, req) {
77+ // Return whatever URL comes from the request as the text body
88+ return new Response(`Url: ${req.url}`);
99+ },
1210});
13111412export const registry = setup({
1515- use: { counter },
1616-});1313+ use: { http },
1414+});
+21
start_gateway.ts
···11+import { createClient } from "rivetkit/client";
22+import { registry } from "./registry";
33+import { serve } from "@hono/node-server";
44+import { Hono } from "hono";
55+66+// Connect to Rivet
77+const client = createClient<typeof registry>();
88+99+// Get the http handler actor
1010+const http = client.http.getOrCreate("main");
1111+1212+// Create a webserver
1313+const app = new Hono();
1414+1515+// Forward all requests to the http handler
1616+app.all("*", (c) => http.fetch(c.req.raw));
1717+1818+// Run the node.js webserver
1919+serve(app, (info) => {
2020+ console.log(`Listening on http://localhost:${info.port}`);
2121+});