Embedded
Next.js
Mount Bullstudio in a Next.js App Router route handler.
Bullstudio supports Next.js App Router route handlers. The Pages Router is not supported.
Install
pnpm add @bullstudio/next @bullstudio/bullmq-adapter bullmq ioredisQueue module
// lib/queue.ts
import { Queue } from "bullmq";
import IORedis from "ioredis";
export const connection = new IORedis(process.env.REDIS_URL!, {
maxRetriesPerRequest: null,
});
export const emailQueue = new Queue("email", { connection });Route handler
Create a catch-all route whose folder matches mountPath.
// app/ops/bullstudio/[[...bullstudio]]/route.ts
import { createBullMqQueueAdapter } from "@bullstudio/bullmq-adapter";
import { bullstudio } from "@bullstudio/next";
import { emailQueue } from "@/lib/queue";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export const { GET, HEAD, POST } = bullstudio({
mountPath: "/ops/bullstudio",
queues: [
createBullMqQueueAdapter(emailQueue, {
key: "email",
label: "Email",
}),
],
protection: {
type: "session",
username: process.env.BULLSTUDIO_USERNAME ?? "operator",
password: process.env.BULLSTUDIO_PASSWORD!,
sessionSecret: process.env.BULLSTUDIO_SESSION_SECRET!,
},
});Open /ops/bullstudio.
Mount path
mountPath must match the route folder.
| Route file | mountPath |
|---|---|
app/ops/bullstudio/[[...bullstudio]]/route.ts | /ops/bullstudio |
app/admin/queues/[[...bullstudio]]/route.ts | /admin/queues |