Hono Dashboard Adapter
The @infrakit/adapter/hono package provides a simple way to integrate the InfraKit dashboard into a Hono application, making it easy to add observability to your modern, edge-ready projects.
Installation
First, install the adapter along with Hono and the InfraKit SDK.
bun add @infrakit/adapter/hono hono @infrakit/sdk @infrakit/modules/kvUsage
The HonoAdapter creates a Hono app instance that you can mount as a route in your main application using app.route().
Complete Example
Here is a complete example of setting up a Hono server with the InfraKit dashboard.
import { HonoAdapter } from "@infrakit/adapter/hono";import { KeyValueMemoryAdapter } from "@infrakit/modules/kv";import { InfraKit } from "@infrakit/sdk";import { Hono } from "hono";
// 1. Initialize InfraKit with your desired modulesconst infrakit = new InfraKit({ keyValue: new KeyValueMemoryAdapter(),});
// (Optional) Seed your adapter with some datainfrakit.keyValue.set({ key: "example-key", value: "Hello from Hono!" });
// 2. Initialize the HonoAdapterconst honoAdapter = new HonoAdapter({ baseUrl: "/dashboard", // The URL prefix for the dashboard infrakit,});
// 3. Create your Hono app and mount the dashboard routeconst app = new Hono();app.route("/dashboard", honoAdapter.endpoint);
// Your other application routesapp.get("/", (c) => c.text("Your main application is running!"));
export default app;How It Works
baseUrl: "/dashboard"informs the adapter of its public path, ensuring all asset and API links are generated correctly.app.route("/dashboard", honoAdapter.endpoint)mounts the entire dashboard, including its UI and API endpoints, under the/dashboardpath.- The adapter handles all incoming requests under
/dashboardand serves either the dashboard UI or the appropriate API response.
Now, when you run your Hono application, the InfraKit dashboard will be accessible at /dashboard.