Next.js Integration

April 20, 2026 · View on GitHub

ostr.io pre-rendering integration options for Next.js apps. Two first-class paths are supported in-app; several additional integrations route bot traffic without touching your Next.js code at all.

ostrio-prerendering-nextjs-support_web

Contents

Pick an integration

OptionWhere it runsCode changesBest for
Self-managed middleware.tsNext.js middleware (edge)Copy one fileFull control, no extra dependency
seo-middleware-nextjs NPM packageNext.js middleware (edge)One-line importMaintained bot list & fewer moving parts
Vercel Routing MiddlewareVercel edge (before Next.js)Copy one fileDeployed to Vercel, framework-agnostic
Cloudflare WorkerCloudflare edgeNoneDNS on Cloudflare, zero app changes
Netlify integrationNetlify edgeNoneDeployed on Netlify Pro/Enterprise
Nginx / Apache / CaddyReverse proxyNoneSelf-hosted Next.js behind a proxy

Option 1 — Self-managed middleware.ts

Copy examples/next.js/middleware.ts to the project root or /src/ directory. The file is a complete, ready-to-deploy middleware.ts that detects bot traffic using the canonical crawler regex and proxies matching requests to https://render.ostr.io.

Set the OSTR_AUTH environment variable (Basic <base64 user:password> from the ostr.io pre-rendering panel) in your deployment environment.

No extra npm dependency is required — the middleware uses only NextRequest / NextResponse.

Option 2 — seo-middleware-nextjs NPM package

Maintained Next.js wrapper around spiderable-middleware. One-line import into your middleware.ts; bot list, renderer routing, and configuration defaults are kept up to date upstream.

Pick this option when you want the bot-detection list and renderer upgrade path to be maintained by the spiderable-middleware family of packages rather than copy-pasting a file.

Option 3 — Infrastructure-level (no code changes)

When you cannot modify middleware.ts — or you prefer to keep pre-rendering concerns out of the app — route bot traffic before Next.js ever sees it:

Validation

Bot request should return a pre-rendered snapshot with X-Prerender-Id:

curl -sI -A 'Googlebot/2.1' https://yourdomain.com/some-page

Regular browser request should pass through to Next.js:

curl -sI -A 'Mozilla/5.0' https://yourdomain.com/some-page

References