'use strict';

const Hapi = require('hapi');

const server = new Hapi.Server();
server.connection({ host: '127.0.0.1', port: 8000 });

// Add Crumb plugin

server.register({ register: require('../'), options: { restful: true } }, (err) => {

    if (err) {
        throw err;
    }
});

server.route([

    // a "crumb" cookie gets set with any request when not using views

    {
        method: 'GET',
        path: '/generate',
        handler: function (request, reply) {

            // return crumb if desired
            return reply('{ "crumb": ' + request.plugins.crumb + ' }');
        }
    },

    // request header "X-CSRF-Token" with crumb value must be set in request for this route

    {
        method: 'PUT',
        path: '/crumbed',
        handler: function (request, reply) {

            return reply('Crumb route');
        }
    }
]);

server.start(() => {

    console.log('Example restful server running at:', server.info.uri);
});

@@ -538,23 +538,16 @@
 ply(
-'
 %7B 
-%22
 crumb
-%22: ' +
+:
  req
@@ -569,14 +569,9 @@
 umb 
-+ ' %7D'
+%7D
 );%0A 

Update restful example to respond with JSON. Closes #64