Skip to content

Instantly share code, notes, and snippets.

@kevboutin
Created February 26, 2016 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevboutin/5e7ac37d17aa034538b7 to your computer and use it in GitHub Desktop.
Save kevboutin/5e7ac37d17aa034538b7 to your computer and use it in GitHub Desktop.
Shows how to use hapi within node to manage state with cookies.
'use strict';
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ port: 8000 });
server.state('hello', {
//ttl = time to live
ttl: 60 * 60 * 1000,
isHttpOnly: true,
encoding: 'iron',
password: 'a5LewP10pXNbWUdYQakUfVlk1jUVuLuUU6E1WEE302k'
});
server.route({
method: 'GET',
path: '/',
config: {
handler: function(request, response) {
let hello = request.state.hello.name;
response('Cookies!' ${hello});
.state('hello', { name: 'kevin' })
}
}
});
server.start(() => console.log(`Started at ${server.info.uri}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment