Skip to content

Instantly share code, notes, and snippets.

@pon
Created July 30, 2015 20:04
Show Gist options
  • Save pon/df5a1f22c4409db1c50c to your computer and use it in GitHub Desktop.
Save pon/df5a1f22c4409db1c50c to your computer and use it in GitHub Desktop.
hapi.js
var Bluebird = require('bluebird');
var Hapi = require('hapi');
var Server = new Hapi.Server();
Server.connection({ port: 3000 });
Server.method('pAdd', function (a, b) {
return Bluebird.resolve(a + b);
});
Server.route({
method: 'GET',
path: '/',
config: {
pre: [
{ method: 'pAdd(1, 2)', assign: 'val' } // Never resolves
],
handler: function (request, reply) {
reply(Server.methods.pAdd(1, 2)); // Resolves and replies
}
}
});
Server.start();
console.log('Server started on', Server.info.uri);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment