Route Handlers
Publishing events
Use the shared synkro client inside any App Router route handler.
import { NextResponse } from "next/server";import { synkro } from "@/lib/synkro";
export async function POST(request: Request) { const body = await request.json(); const requestId = await synkro.publish("order.created", body); return NextResponse.json({ requestId });}Mounting the dashboard
Create a catch-all route that forwards requests to the dashboard handler.
import { createDashboardHandler } from "@synkro/next";import { synkro } from "@/lib/synkro";
const handler = createDashboardHandler(synkro, { basePath: "/synkro" });
export const GET = handler;The dashboard is now available at /synkro.
Registering event handlers
Register handlers by calling synkro.on() in your shared module or in a route handler that runs at startup.
import { createSynkro } from "@synkro/next";
export const synkro = createSynkro({ transport: "redis", connectionUrl: process.env.REDIS_URL!,});
// Register handlers — these attach once the instance initializessynkro.on("order.created", async (payload) => { console.log("Order created:", payload);});