hapi-common-log
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -1,4 +0,4 @@ | ||
var moment = require('moment-tokens'); | ||
var moment = require('moment-tokens'); | ||
module.exports = function toCommonLogFormat (request) { | ||
module.exports = function toCommonLogFormat (request, options) { | ||
@@ -11,3 +11,3 @@ var rawReq = request.raw.req; | ||
var clientIp = request.info.remoteAddress, | ||
var clientIp = options && options.ipHeader && request.headers[options.ipHeader] || request.info.remoteAddress, | ||
clientId = '-', | ||
@@ -14,0 +14,0 @@ userid = request.id, |
{ | ||
"name": "hapi-common-log", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Parses the hapi request object to create a common log format log line", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -21,2 +21,12 @@ | ||
## Options | ||
Sometimes you want a specific header for incoming client IP (i.e. if you've got a proxy). To customize: | ||
```js | ||
toCommonLogFormat(request, { ipHeader: 'x-forwarded-to' }); | ||
``` | ||
## The Common Log Format | ||
@@ -23,0 +33,0 @@ |
@@ -56,2 +56,24 @@ var Lab = require('lab'), | ||
}); | ||
}); | ||
describe('handling options', function () { | ||
it('looks up IP from the header if desired', function (done) { | ||
server.ext('onRequest', function (request, next) { | ||
request.headers['x-forwarded-to'] = '123.45.678'; | ||
next(); | ||
}); | ||
server.ext('onPostHandler', function (request, next) { | ||
var clf = toCommonLogFormat(request, {ipHeader: 'x-forwarded-to'}); | ||
var components = clf.split(' '); | ||
expect(components[0]).to.equal('123.45.678'); | ||
next(); | ||
}); | ||
server.inject({url: '/'}, function () { | ||
done(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5864
72
52