Install · runtime

The agent on Next.js

Runs before the response. In Next.js the agent is the middleware file, App Router or Pages Router alike.

By Reflexa Technologies — the team building Reflexa, the agent that works on your site · updated 16 October 2026

How it works on Next.js

In Next.js the agent is the middleware file, App Router or Pages Router alike. On Vercel or self-hosted, the file is the same.

The file

middleware.ts — At your project root, beside app/ or pages/.

import { NextResponse } from 'next/server'
import { reflexa } from './reflexa-agent.js'

const agent = reflexa({ token: process.env.REFLEXA_TOKEN })

export async function middleware(request) {
  try {
    return (await agent.ahead(request)) ?? NextResponse.next()
  } catch {
    return NextResponse.next()
  }
}

export const config = { matcher: '/:path*' }

Get reflexa-agent.js and the site's token from the dashboard's Agent page, put the token in REFLEXA_TOKEN, deploy. Then press Check the connection in the dashboard: it fetches the domain proof from your real domain and the agent is live.

What this install serves

What it does not: it never sees the page, so robots.txt and Organization data are not switches here — the agent says so instead of pretending. Connect the site's repository in the dashboard and the agent commits those, and a page's title, description, opening and FAQ, itself.

How installing the agent works, in general → · what the agent does and never does →

Questions people ask.

Does anything change on the site when I install it?

No. Installing puts the agent in place and binds it to the site by its token; nothing is applied. Every switch is your click in the dashboard and every word it writes is shown to you first.

Can I take it out?

Remove the file and redeploy. Whatever was last switched on stops being served on the next request. Your checks and the agent's memory stay in your Reflexa account.

What can this install actually do?

Counts every AI visit, page by page. Serves /llms.txt. Serves the domain proof that binds the token to this host. It never sees the page, so robots.txt and Organization data are not switches here — the agent says so instead of pretending. Connect the site's repository in the dashboard and the agent commits those, and a page's title, description, opening and FAQ, itself.

Is the token a secret?

Yes — it belongs to this one site and should live in an environment variable, never in a file you commit. It grants nothing beyond this site, and the domain proof refuses it from any other host.

Read your site first. Then put the agent on it.

The 23 checks run from outside before anything is installed — you see what the agent would do before it does it.

Run the free check →