Files
zopu-code/.agents/skills/chat-room/reference/general/http-server.md

2.5 KiB

HTTP Server

Source: src/content/docs/general/http-server.mdx Canonical URL: https://rivet.dev/docs/general/http-server Description: Different ways to run your RivetKit HTTP server.


Methods of Running Your Server

registry.start()

The simplest way to run your server. Starts a local RivetKit server, serves static files from a public directory, and starts the actor runner:

Run with npx tsx --watch index.ts (Node.js), bun --watch index.ts (Bun), or deno run --allow-net --allow-read --allow-env --watch index.ts (Deno). Clients connect to the Rivet Engine on http://localhost:6420.

With Fetch Handlers

A fetch handler is a function that takes a Request and returns a Response. This is the standard pattern used by Cloudflare Workers, Deno Deploy, Bun, and other modern runtimes.

Use registry.serve() to get a fetch handler:

To integrate with a router like Hono or Elysia, use registry.handler():

Hono

Elysia

Then run your server:

npx tsx --watch server.ts
bun --watch server.ts
deno run --allow-net --allow-read --allow-env --watch server.ts

Explicit HTTP Server

If you need to explicitly start the HTTP server instead of using the fetch handler pattern:

Node.js (Hono)

Using Hono with @hono/node-server:

Node.js (Adapter)

Using @whatwg-node/server to adapt the fetch handler to Node's HTTP server:

import { actor, setup } from "rivetkit";
import { createServer } from "node:http";
import { createServerAdapter } from "@whatwg-node/server";

const myActor = actor({ state: {}, actions: {} });
const registry = setup({ use: { myActor } });

const handler = createServerAdapter(registry.serve().fetch);
const server = createServer(handler);
server.listen(3000);

Bun

Using Bun's native server:

import { actor, setup } from "rivetkit";

const myActor = actor({ state: {}, actions: {} });
const registry = setup({ use: { myActor } });

Bun.serve({
  port: 3000,
  fetch: (request: Request) => registry.handler(request),
});

Deno

Using Deno's native server:

import { actor, setup } from "rivetkit";

const myActor = actor({ state: {}, actions: {} });
const registry = setup({ use: { myActor } });

Deno.serve({ port: 3000 }, (request: Request) => registry.handler(request));

Source doc path: /docs/general/http-server