intercom-for-hapi
v1.0.0
Published
easily access the intercom client from within your Hapi app
Downloads
27
Readme
Intercom for Hapi
A Hapi plugin for quickly accessing the Intercom for Node client.
Installation
npm install intercom-for-hapi --save
yarn add intercom-for-hapi --save
Getting Started
The purpose of this plugin is simply to allow you to instantiate the Intercom client once and then make it accessible to your entire Hapi application.
Example
var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection({ host: 'localhost' });
var options = {
token: '123sds88' // REQUIRED
};
// Register the plugin
server.register({
register: require('intercom-for-hapi'),
options: options
}, function (err) {
if (err) {
console.error(err);
}
else {
server.start(function () {
console.info('Server started at ' + server.info.uri);
});
}
});
// Declare a route that uses it
server.route( {
'method': 'GET',
'path': '/users',
'handler': usersHandler
});
function usersHandler (request, reply) {
var client = request.intercom; // also available via request.server.app.intercom
client.users.list(function (res) {
return reply(res);
});
};
server.start(function() {
console.log("Server started at " + server.info.uri);
});