/prerender-varnish

prerender-varnish is a Varnish configuration for serving pre-rendered HTML from Javascript pages/apps using prerender.io.

Primary LanguagePythonMIT LicenseMIT

prerender-varnish

prerender-varnish is a Varnish 3 configuration for serving pre-rendered HTML from Javascript pages/apps using prerender.io.

prerender-varnish is currently in a pre-alpha state. Anything can and likely will change.

Using prerender-varnish

To use prerender-varnish, symlink prerender.vcl and prerender_backend.vcl in your Varnish configuration directory (usually /etc/varnish) and add them to your primary Varnish configuration file:

include "prerender.vcl";

Updating prerender.io backend

The prerender.io rendering service is hosted on Heroku and Heroku (and AWS ELB) domains resolve to multiple IP addresses. Varnish currently requires backend hosts to resolve to a single unchanging IP address. As a workaround, backend_generator.py will query DNS for the prerender.io rendering service, generate a Varnish director containing all rendering service IP addresses, write it to prerender_backend.vcl, and reload Varnish when the configuration changes.

Run backend_generator.py as follows:

Usage: backend_generator.py [options]

Generate a Varnish backend configuration given a hostname.

Options:
  -h, --help            show this help message and exit
  -n HOSTNAME, --hostname=HOSTNAME
                        prerender.io rendering backend hostname [default:
                        service.prerender.io]
  -p PORT, --port=PORT  prerender.io rendering backend port [default: 80]
  -d BACKEND_CONF, --dest=BACKEND_CONF
                        varnish backend conf file to overwrite [default:
                        /etc/varnish/prerender_backend.vcl]
  -r, --reload-varnish  reload varnish on completion [default: False]
  -v, --verbose         show verbose output [default: False]
  --dry-run             don't write to conf file or reload Varnish [default:
                        False]

With TTLs for these DNS records set quite low, it is advised to run this very frequently. Once per minute should be sufficient.

License

The MIT License (MIT)

Copyright (c) 2013 Matthew Walker

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.