Skip to content

Commit fee1b34

Browse files
committed
DD-718 Add ability to log realClientIp
1 parent 5c69e2d commit fee1b34

5 files changed

Lines changed: 179 additions & 300 deletions

File tree

lib/logger.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,22 @@ Logger.tokens = {
176176
return Array.isArray(header) ? header.join(', ') : header;
177177
}),
178178

179+
realClientIp: new TokenFn(function () {
180+
if (!this.req) { return; }
181+
182+
console.log('This should be the real-client-ip (might not appear locally): ' + this.req.get('x-real-client-ip'));
183+
console.log('This should be forwarded-for (might not appear locally): ' + this.req.get('x-forwarded-for'));
184+
console.log('This should be Host (should ALWAYS appear): ' + this.req.get('host'));
185+
console.log('This should be all headers: ' + this.req.headers);
186+
187+
return this.req.headers['x-real-client-ip']; // This is temporary because the other 2 headers don't get set when running locally
188+
}),
189+
179190
clientip: new TokenFn(function () {
180191
if (!this.req) { return; }
192+
// return 'Pretend this is an IP!';
181193
return this.req.ip || (this.req.connection && this.req.connection.remoteAddress);
194+
// return this.req.headers['x-real-client-ip'];
182195
}),
183196

184197
request: new TokenFn(function () {

lib/manager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ Manager.defaultOptions = {
257257
},
258258
requestMeta: {
259259
clientip: 'clientip',
260+
realClientIp: 'realClientIp',
260261
uniqueID: 'req.x-uniq-id',
261262
remoteAddress: 'connection.remoteAddress',
262263
hostname: 'hostname',

0 commit comments

Comments
 (0)