Framework Adapters

Fastify Integration

Pair Taser.js file routing with Fastify. Coexist with Fastify plugins, hooks, and native route handlers using host pass-through architecture.

Taser.js integrates with Fastify applications using the Host Pass-Through Architecture. You can run Fastify plugins, hooks, and legacy endpoints alongside Taser.js's file-based route tree.


How It Works

  1. Taser.js First: Taser.js evaluates requests against src/routes/.
  2. Fastify Fall-Through: Unmatched requests fall through to Fastify's internal router.
  3. 404 Handling: If neither handles the request, Taser.js returns 404 Not Found.

Quickstart

1. Scaffold with Fastify Host

pnpm create taserjs@latest my-fastify-app --framework fastify -y

2. Configure src/server.node.ts

Create src/server.node.ts exporting Fastify's routing handler:

src/server.node.ts
import Fastify from "fastify";

const app = Fastify({ logger: true });

// Existing Fastify endpoints:
app.get("/fastify-legacy", async () => {
  return { framework: "Fastify", status: "online" };
});

// Ensure Fastify plugins and routes are loaded before export:
await app.ready();

export default app.routing;

3. Import the Compiled Taser.js App (optional host wiring)

import { app } from "./.taserjs/routes.gen.js";

export default app; // Hono instance compiled from defineTaser() + src/routes/

4. Add Taser.js Routes

Create src/routes/health.get.ts:

src/routes/health.get.ts
import { json } from "@taserjs/router/reply";
import { t } from "@taserjs/router";

const GET = t.get("/health");

export default GET.handler(() => {
  return json({ ok: true, timestamp: Date.now() });
});

Full Fastify Migration Guide

For a comprehensive walkthrough of Fastify plugin and route conversion, middleware mapping, and known limitations, check out the dedicated Migration Guide.


Next Steps