Vercel Integration

April 20, 2026 ยท View on GitHub

Self-managed Vercel Routing Middleware that routes bot traffic to the ostr.io pre-rendering CDN. One file, zero config, works with any framework deployed to Vercel.

What it does

Vercel Routing Middleware runs on every request before the CDN cache. The supplied middleware:

  1. Lets non-GET/HEAD traffic pass through to origin unchanged.
  2. Skips static assets and /.well-known/ paths.
  3. Checks the User-Agent against the canonical crawler regex and handles the legacy _escaped_fragment_ query parameter.
  4. For bot traffic, proxies the request to https://render.ostr.io with your OSTR_AUTH header.
  5. On any renderer error, falls back to your origin response (fail-open).

When to use

  • You deploy to Vercel and want pre-rendering without touching your framework code.
  • You want edge-level routing โ€” middleware runs before the CDN cache.
  • You use a framework that does not expose its own middleware hook, or you want a single integration that is independent of the framework (Astro, SvelteKit, Nuxt, Remix, plain static, etc.).

For Next.js specifically, the dedicated Next.js middleware / NPM package is another good option and runs in the same runtime.

Framework compatibility

The middleware is framework-agnostic. Works with any framework deployed to Vercel:

Setup

The complete drop-in middleware, env-var reference, and deploy steps live in examples/vercel/. High-level flow:

  1. Copy examples/vercel/middleware.js to your project root.
  2. Install @vercel/functions.
  3. Set OSTR_AUTH (from the ostr.io pre-rendering panel) and, if needed, ROOT_URL as Vercel environment variables.
  4. Deploy.

See the example README for full details.

Validation

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

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

Regular browser request should pass through untouched:

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