Framework Adapters

Fastify Integration

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

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


How It Works

  1. Taser First: Taser 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 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. Add Taser 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() });
});

Next Steps