mtharrison / hapi-etags

A plugin for hapi.js that generates etags for your responses
MIT License
10 stars 4 forks source link

hapi-etags


hapi will automatically generate ETag headers for your responses when you use the file handler or reply.file() method. But if you're using any other kind of response (such as JSON, HTML, text etc) you won't get ETags for free. This plugin fixes that!

Installation and configuration

To install, just add to your npm deps:

npm install --save hapi-etags

Then register the plugin:

server.register([
    {
        register: require('hapi-etags'),
        options: {
            // explained below
        }
    }
], function (err) {

    if (err) {
        throw err;
    }

    server.start(function () {
        console.log('Started!');
    });

});

The following options are available when registering the plugin [defaults]:

Advice and warnings

Only the plain and buffer varieties are set by default. Support for the other varieties should be considered experimental. Here's some issues to be aware of: