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
37 changes: 37 additions & 0 deletions examples/hono-bun/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Hono + Bun Integration for RivetKit

Example project demonstrating Hono web framework with Bun runtime integration with [RivetKit](https://rivetkit.org).

[Learn More →](https://github.com/rivet-dev/rivetkit)

[Discord](https://rivet.dev/discord) — [Documentation](https://rivetkit.org) — [Issues](https://github.com/rivet-dev/rivetkit/issues)

## Getting Started

### Prerequisites

- Bun

### Installation

```sh
git clone https://github.com/rivet-dev/rivetkit
cd rivetkit/examples/hono-bun
npm install
```

### Development

```sh
npm run dev
```

Test the server by running:

```sh
curl -X POST http://localhost:8080/increment/test
```

## License

Apache 2.0
28 changes: 28 additions & 0 deletions examples/hono-bun/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "example-hono-bun",
"version": "2.0.9",
"private": true,
"type": "module",
"scripts": {
"dev": "bun --watch src/server.ts",
"check-types": "tsc --noEmit",
"connect": "tsx scripts/connect.ts"
},
"devDependencies": {
"@types/bun": "^1.1.15",
"rivetkit": "workspace:*",
"typescript": "^5.5.2"
},
"dependencies": {
"hono": "^4.7.0"
},
"keywords": [
"rivetkit",
"hono",
"bun",
"actor",
"stateful",
"example"
],
"stableVersion": "0.8.0"
}
22 changes: 22 additions & 0 deletions examples/hono-bun/scripts/connect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { createClient } from "rivetkit/client";
import type { Registry } from "../src/registry";

async function main() {
const client = createClient<Registry>("http://localhost:8080/rivet");

const counter = client.counter.getOrCreate().connect();

counter.on("newCount", (count: number) => console.log("Event:", count));

for (let i = 0; i < 5; i++) {
const out = await counter.increment(5);
console.log("RPC:", out);

await new Promise((resolve) => setTimeout(resolve, 1000));
}

await new Promise((resolve) => setTimeout(resolve, 10000));
await counter.dispose();
}

main();
15 changes: 15 additions & 0 deletions examples/hono-bun/src/registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { actor, setup } from "rivetkit";

export const counter = actor({
state: { count: 0 },
actions: {
increment: (c, x: number) => {
c.state.count += x;
return c.state.count;
},
},
});

export const registry = setup({
use: { counter },
});
38 changes: 38 additions & 0 deletions examples/hono-bun/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Hono } from "hono";
import { upgradeWebSocket, websocket } from "hono/bun";
import { registry } from "./registry";

const { client, fetch } = registry.start({
basePath: "/rivet",
// Hono requires using Hono.serve
disableDefaultServer: true,
// Override endpoint
overrideServerAddress: "http://localhost:8080/rivet",
// Specify Hono-specific upgradeWebSocket
getUpgradeWebSocket: () => upgradeWebSocket,
});

// Setup router
const app = new Hono();

app.use("/rivet/*", async (c) => {
return await fetch(c.req.raw, c.env);
});

// Example HTTP endpoint
app.post("/increment/:name", async (c) => {
const name = c.req.param("name");

const counter = client.counter.getOrCreate(name);
const newCount = await counter.increment(1);

return c.text(`New Count: ${newCount}`);
});

Bun.serve({
port: 8080,
fetch: app.fetch,
websocket,
});

console.log("Listening at http://localhost:8080");
43 changes: 43 additions & 0 deletions examples/hono-bun/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "esnext",
/* Specify a set of bundled library declaration files that describe the target runtime environment. */
"lib": ["esnext"],
/* Specify what JSX code is generated. */
"jsx": "react-jsx",

/* Specify what module code is generated. */
"module": "esnext",
/* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "bundler",
/* Specify type package names to be included without being referenced in a source file. */
"types": ["bun"],
/* Enable importing .json files */
"resolveJsonModule": true,

/* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
"allowJs": true,
/* Enable error reporting in type-checked JavaScript files. */
"checkJs": false,

/* Disable emitting files from a compilation. */
"noEmit": true,

/* Ensure that each file can be safely transpiled without relying on other imports. */
"isolatedModules": true,
/* Allow 'import x from y' when a module doesn't have a default export. */
"allowSyntheticDefaultImports": true,
/* Ensure that casing is correct in imports. */
"forceConsistentCasingInFileNames": true,

/* Enable all strict type-checking options. */
"strict": true,

/* Skip type checking all .d.ts files. */
"skipLibCheck": true
},
"include": ["src/**/*"]
}
4 changes: 4 additions & 0 deletions examples/hono-bun/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://turbo.build/schema.json",
"extends": ["//"]
}
42 changes: 39 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading