Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
cache remoteAddress to avoid undefined
  • Loading branch information
bahamas10 committed Nov 15, 2013
1 parent 1797c8f commit f8717ee
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Expand Up @@ -10,6 +10,7 @@ function accesslog(req, res, format, cb) {
format = null;
}

var remoteAddress = req.connection.remoteAddress;
format = format || defaultformat;
cb = cb || console.log.bind(console);

Expand Down Expand Up @@ -56,8 +57,8 @@ function accesslog(req, res, format, cb) {
':endDate': end.toISOString(),
':endTime': end.getTime(),
':httpVersion': req.httpVersion,
':ip': req.connection.remoteAddress || '-',
':Xip': encode(req.headers['x-forwarded-for'] || req.connection.remoteAddress || '-'),
':ip': remoteAddress || '-',
':Xip': encode(req.headers['x-forwarded-for'] || remoteAddress || '-'),
':method': req.method,
':protocol': req.connection.encrypted ? 'HTTPS' : 'HTTP',
':referer': encode(req.headers.referer || '-'),
Expand Down

0 comments on commit f8717ee

Please sign in to comment.