Skip to content

Commit

Permalink
Merge pull request #24 from JordanHood/master
Browse files Browse the repository at this point in the history
Updating to Hapi 17.x.x
  • Loading branch information
mac- committed Dec 14, 2017
2 parents 0bf80e7 + d0e5b64 commit 6553876
Show file tree
Hide file tree
Showing 6 changed files with 1,517 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: node_js
node_js:
- 4
- 8
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ server.statsd.set('your.set', 200);
* 4.x.x - Hapi 11.x.x
* 5.x.x - Hapi 13.x.x
* 6.x.x - Hapi 16.x.x
* 7.x.x - Hapi 17.x.x (Node v8)

# License

Expand Down
20 changes: 13 additions & 7 deletions lib/hapi-statsd.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var StatsdClient = require('statsd-client'),
template: '{path}.{method}.{statusCode}'
};

module.exports.register = function (server, options, next) {
var register = function (server, options) {
var settings = Hoek.applyToDefaults(defaults, options || {}),
statsdClient = options.statsdClient || new StatsdClient({
host: settings.host,
Expand All @@ -23,12 +23,12 @@ module.exports.register = function (server, options, next) {

server.decorate('server', 'statsd', statsdClient);

server.ext('onPreResponse', function (request, reply) {
server.ext('onPreResponse', function (request, h) {
var startDate = new Date(request.info.received);
var statusCode = (request.response.isBoom) ? request.response.output.statusCode : request.response.statusCode;

var path = request._route.path;
var specials = request.connection._router.specials;
var specials = request._core.router.specials;

if (request._route === specials.notFound.route) {
path = '/{notFound*}';
Expand All @@ -49,12 +49,18 @@ module.exports.register = function (server, options, next) {
statsdClient.increment(statName);
statsdClient.timing(statName, startDate);

reply.continue();
return h.continue;
});

next();
};

module.exports.register.attributes = {
pkg: require('../package.json')
var pkg = require('../package.json');
var name = pkg['name'];
var version = pkg['version'];

exports.plugin = {
register: register,
name: name,
version: version,
pkg: pkg
};

0 comments on commit 6553876

Please sign in to comment.