open-index/open-npm huggingface dataset:
npm package: @skg-global/rendertron-middleware
Description: Express middleware for the rendertron service.
Author: Bui Van Binh
Latest version: 0.1.21

# rendertron-middleware

An Express middleware for Rendertron
Rendertron is a server which runs headless Chrome and renders web pages on the fly, which can be set up to serve pages to search engines, social networks and link rendering bots.

This middleware checks the User-Agent header of incoming requests, and if it matches one of a configurable set of bots, proxies that request through Rendertron.

## Usage
```sh
$ npm install --save express skg-rendertron-middleware
```

```js
const express = require('express');
const rendertron = require('@skg-global/rendertron-middleware');

const app = express();

app.use(rendertron.makeMiddleware({
  proxyUrl: 'http://my-rendertron-instance/render',
}));

app.use(express.static('files'));
app.listen(8080);
```

## Configuration

The `makeMiddleware` function takes a configuration object with the following
properties:

| Property | Default | Description |
| -------- | ------- | ----------- |
| `proxyUrl` | *Required* | Base URL of your running Rendertron proxy service. |
| `apiKey` | *Required* | The API used for running Rendertron proxy service. |
| `userAgentPattern` | A set of known bots that benefit from pre-rendering. | RegExp for matching requests by User-Agent header. |
| `excludeUrlPattern` | A set of known static file extensions. | RegExp for excluding requests by the path component of the URL. |
| `injectShadyDom` | `false` | Force the web components polyfills to be loaded. [Read more.](https://github.com/samuelli/bot-render#web-components) |
| `timeout` | `11000` | Millisecond timeout for the proxy request to Rendertron. If exceeded, the standard response is served (i.e. `next()` is called). See also the [Rendertron timeout.](https://github.com/samuelli/bot-render#rendering-budget-timeout) |