Skip to content
LogoLogo

Using Hono

Bullet inside a Hono server

bullet() returns an H3 application with a standard .fetch handler. Hono's .mount() accepts any WinterTC-compliant fetch handler, so you can embed Bullet at the root and add your own Hono routes alongside it.

Install Hono

Create server.ts

Mount Bullet at / so it handles everything Hono does not match first. Use serve() from crossws/server instead of @hono/node-server: the crossws variant wraps srvx and attaches the WebSocket upgrade handler that Bullet's HMR and DevTools connections require.

server.ts
import { bullet } from "@clutchify/bullet-server";
import { Hono } from "hono";
import { serve } from "crossws/server";
 
import configuration from "./rspack.config.ts";
 
const port = Number(process.env.REPACK_PORT ?? 8081);
const host = process.env.REPACK_HOST;
 
const bulletApp = await bullet({
	configuration,
	mode: process.env.NODE_ENV === "production" ? "production" : "development",
 
	environments: {
		client: "client",
		server: "server",
 
		android: "android",
		ios: "ios",
	},
 
	development: { port, host },
});
 
const app = new Hono()
	.get("/health", (c) => c.json({ status: "ok" }))
	.mount("/", bulletApp.fetch);
 
serve({ fetch: app.fetch, hostname: host, port, websocket: {} });

Hono handles routes you register explicitly. Any request that falls through reaches mount("/", ...) and goes to Bullet.