Rendertron Express Middleware

raw JSON →
0.1.5 verified Thu Apr 23 auth: no javascript abandoned

This package provides an Express middleware designed to facilitate dynamic rendering for web applications by integrating with a Rendertron service. It operates by inspecting incoming HTTP requests' User-Agent headers, and if a known bot or crawler is detected, it proxies the request to a separately deployed Rendertron instance. The Rendertron service, in turn, renders the page using a headless Chrome instance, returning static HTML suitable for search engines and social media bots that may not execute client-side JavaScript. The current stable version of this middleware is 0.1.5, which was last published over 7 years ago. The upstream Rendertron project itself has been officially deprecated since October 2022, with its maintainers stating that dynamic rendering is no longer the recommended approach for SEO. Consequently, this `rendertron-middleware` package is effectively abandoned and no longer maintained.

error Error: Missing proxyUrl configuration
cause The `proxyUrl` property was not provided or was an empty string in the `makeMiddleware` configuration object.
fix
Set the proxyUrl in the middleware configuration to the full URL of your Rendertron render endpoint: app.use(rendertron.makeMiddleware({ proxyUrl: 'http://your-rendertron-url/render' }));
error Bots are not receiving pre-rendered content / My pages are not indexed by search engines.
cause The `userAgentPattern` is not correctly matching the User-Agent string of the bot, or the `excludeUrlPattern` is inadvertently blocking requests from being proxied to Rendertron. Alternatively, the Rendertron service itself might be misconfigured or unreachable.
fix
Verify that your userAgentPattern regex correctly includes the User-Agents of the bots you want to target (e.g., new RegExp('googlebot|bingbot', 'i')). Check your excludeUrlPattern to ensure it's not filtering legitimate prerendering requests. Confirm your Rendertron service is running and accessible at the proxyUrl.
breaking The main Rendertron project (GoogleChrome/rendertron) has been officially deprecated since October 2022. Dynamic rendering is no longer recommended for SEO, as modern search engines are capable of rendering JavaScript. This `rendertron-middleware` package is no longer maintained, and its use for SEO purposes is obsolete.
fix Migrate to server-side rendering (SSR), static site generation (SSG), or ensure your client-side rendered application provides robust SEO for modern crawlers without dynamic rendering. Consider alternatives like Next.js, Nuxt.js, or similar frameworks that inherently support SSR/SSG.
gotcha The `proxyUrl` configuration property is mandatory and must point to a running instance of the Rendertron service. Failing to provide a valid URL will result in runtime errors or incorrect behavior where bot requests are not proxied.
fix Always provide a `proxyUrl` in the `makeMiddleware` configuration object, pointing to your deployed Rendertron service. Example: `proxyUrl: 'https://my-rendertron-instance.appspot.com/render'`.
gotcha Older versions of the Rendertron service (especially 1.x.x and even 3.0.0 with specific bypasses) had known security vulnerabilities, including Server-Side Request Forgery (SSRF) and potential access to cloud metadata endpoints. Running an outdated or improperly configured Rendertron backend with this middleware could expose your infrastructure.
fix Ensure your Rendertron instance (if still in use) is fully patched and configured with all recommended security measures, including domain allow-listing and blocking access to sensitive internal endpoints. However, the primary recommendation is to deprecate Rendertron usage entirely due to its abandoned status.
gotcha The `timeout` option in `rendertron-middleware` only controls the middleware's proxy request timeout. The actual rendering budget and timeout for the Rendertron service itself are configured separately on the Rendertron instance (e.g., via `config.json`). If the middleware's timeout is shorter than the Rendertron service's rendering budget, requests might fail prematurely on the middleware side, leading to non-prerendered content being served to bots without the Rendertron service actually failing to render.
fix Align the `timeout` value in the middleware configuration with the `renderingBudgetMs` (or similar) setting on your Rendertron service. Ensure the middleware timeout is sufficiently long to allow the Rendertron service to complete rendering, or handle potential fallback logic for unrendered pages gracefully.
npm install rendertron-middleware
yarn add rendertron-middleware
pnpm add rendertron-middleware

Sets up an Express server with `rendertron-middleware` to proxy requests from detected bots to a specified Rendertron service, serving static files for other requests.

import express from 'express';
import { makeMiddleware } from 'rendertron-middleware';

const app = express();

// Configure the Rendertron middleware
app.use(makeMiddleware({
  // IMPORTANT: Replace with the actual URL of your deployed Rendertron instance.
  // e.g., 'https://my-rendertron-service.appspot.com/render'
  proxyUrl: process.env.RENDERTRON_PROXY_URL ?? 'http://localhost:8081/render',
  // Optional: Custom User-Agent pattern regex for bots to proxy
  // userAgentPattern: new RegExp(['googlebot', 'bingbot'].join('|'), 'i'),
  // Optional: URL path components to exclude from prerendering
  // excludeUrlPattern: new RegExp('\.(js|css|gif|jpg|png|ico|svg)$', 'i'),
  // Optional: Millisecond timeout for the proxy request to Rendertron
  // timeout: 15000
}));

// Serve your static files or application routes AFTER the middleware
app.use(express.static('public'));

const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`Web server listening on port ${PORT}`);
  console.log('Rendertron middleware active.');
});