Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
fix: workaround for express.js 'host' deprecation message (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek authored Jan 10, 2018
1 parent 9b24009 commit a0e7da9
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,9 @@ extend(Raven.prototype, {
});
sources = [{}].concat(sources);
var request = extend.apply(null, sources);
var nonEnumberables = [
var nonEnumerables = [
'headers',
'host',
'hostname',
'ip',
'method',
'protocol',
Expand All @@ -591,12 +591,24 @@ extend(Raven.prototype, {
'url'
];

nonEnumberables.forEach(function(key) {
nonEnumerables.forEach(function(key) {
sources.forEach(function(source) {
if (source[key]) request[key] = source[key];
});
});

/**
* Check for 'host' *only* after we checked for 'hostname' first.
* This way we can avoid the noise coming from Express deprecation warning
* https://github.com/expressjs/express/blob/b97faff6e2aa4d34d79485fe4331cb0eec13ad57/lib/request.js#L450-L452
* REF: https://github.com/getsentry/raven-node/issues/96#issuecomment-354748884
**/
if (!request.hasOwnProperty('hostname')) {
sources.forEach(function(source) {
if (source.host) request.host = source.host;
});
}

return request;
}
});
Expand Down

0 comments on commit a0e7da9

Please sign in to comment.