@rankdeploy/middleware
raw JSON → 1.3.2 verified Sat Apr 25 auth: no javascript
SEO middleware that serves pre-rendered HTML to search engine bots while keeping zero performance impact on human visitors. Current stable version is 1.3.2, with regular updates. Key differentiators: seamless integration with Next.js (single-line setup), Netlify Edge Functions, and Express.js; automatically detects a wide range of bots (Google, Bing, Yandex, social media crawlers, AI bots like GPTBot and Claude); supports custom API URL, extra bots, and exclusion paths. Built by Rank Deploy, it offers a simple, efficient alternative to more complex prerendering solutions.
Common errors
error Cannot find module '@rankdeploy/middleware' or its corresponding type declarations. ↓
cause The module is installed but TypeScript cannot resolve its types.
fix
Ensure your tsconfig.json includes 'node_modules/@types' or install @types/node. Also verify the package is in dependencies (not devDependencies) if you need types in production.
error Expected ';' at 'middleware' (import error in middleware.ts) ↓
cause The Next.js middleware file is imported incorrectly or named export syntax is wrong.
fix
Use export { middleware, config } from '@rankdeploy/middleware/next'. Do not use import or default export.
error Netlify Edge Function import failed: '@rankdeploy/middleware/netlify' is not a valid function handler. ↓
cause The Netlify edge function file does not export the default handler properly.
fix
Ensure the file exports default: export { default } from '@rankdeploy/middleware/netlify'. The file name must match the function name in netlify.toml.
error TypeError: rankdeploy is not a function ↓
cause Trying to use Express import as a default import instead of named import.
fix
Use import { rankdeploy } from '@rankdeploy/middleware/express'. Then call rankdeploy() (note parentheses).
Warnings
gotcha In Next.js, the middleware file must be named middleware.ts (not .js) and located at the project root (not /pages or /app). Also, the export must be a named export of both middleware and config; using a default export will break the integration. ↓
fix Ensure file is middleware.ts at root and export { middleware, config } from '@rankdeploy/middleware/next'.
gotcha Netlify Edge Functions require a netlify.toml configuration with the function name matching the file name. If the file is named other than rankdeploy.ts, the export and config must be adjusted accordingly. ↓
fix Name the file rankdeploy.ts and add [[edge_functions]] function = "rankdeploy" path = "/*" to netlify.toml.
gotcha The Express middleware should be applied before other routes, especially those that handle static files or API endpoints. Applying it after other middleware may cause it to be bypassed for prerender requests. ↓
fix Place app.use(rankdeploy()) as early as possible, before express.static and route handlers.
deprecated The default API URL (https://proxy.unikium.com) may be deprecated in future versions; check documentation for updated endpoint. ↓
fix Consider using createMiddleware to specify a custom apiUrl or watch for changelog updates.
Install
npm install rankdeploy-middleware yarn add rankdeploy-middleware pnpm add rankdeploy-middleware Imports
- middleware, config (Next.js) wrong
import { middleware } from '@rankdeploy/middleware'correctexport { middleware, config } from '@rankdeploy/middleware/next' - default (Netlify) wrong
export default from '@rankdeploy/middleware/netlify'correctexport { default } from '@rankdeploy/middleware/netlify' - rankdeploy (Express) wrong
import rankdeploy from '@rankdeploy/middleware/express'correctimport { rankdeploy } from '@rankdeploy/middleware/express'
Quickstart
// Next.js / Vercel
// File: middleware.ts (at project root)
export { middleware, config } from '@rankdeploy/middleware/next'
// Netlify
// File: netlify/edge-functions/rankdeploy.ts
export { default } from '@rankdeploy/middleware/netlify'
// Express.js
// File: server.ts
import express from 'express'
import { rankdeploy } from '@rankdeploy/middleware/express'
const app = express()
app.use(rankdeploy())
app.listen(3000)