Skip to content

Instantly share code, notes, and snippets.

@daviddias
Last active December 19, 2015 23:08
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 daviddias/6032433 to your computer and use it in GitHub Desktop.
Save daviddias/6032433 to your computer and use it in GitHub Desktop.
// Load modules
var Hapi = require('hapi');
// Declare internals
var internals = {};
internals.profile = function () {
console.log('IF THIS KEEPS RUNNING ITS STRANGE')
this.reply({
'id': 'fa0dbda9b1b',
'name': 'John Doe'
});
};
internals.activeItem = function () {
this.reply({
'id': '55cf687663',
'name': 'Active Item'
});
};
internals.item = function () {
setTimeout(function () {
this.reply({
'id': this.params.id,
'name': 'Item'
});
}, 600);
};
internals.main = function () {
var config = {
cache: {
engine: 'memory'
}
};
var server = new Hapi.Server(8000, config);
server.route([
{ method: 'GET', path: '/profile', config: { handler: internals.profile, cache: {
mode: 'server',
expiresIn: 30000 } } },
{ method: 'GET', path: '/item', config: { handler: internals.activeItem } },
{ method: 'GET', path: '/item/{id}', config: { handler: internals.item, cache: { mode: 'server', expiresIn: 20000, staleIn: 10000, staleTimeout: 500 } } }
]);
server.start();
};
internals.main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment