express-real-ip

Use X-Real-Ip header for req.ip in express

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
express-real-ip
301.0.09 years ago9 years agoMinified + gzip package size for express-real-ip in KB

Readme

Get ip address from custom header

var app = require('express')();
var getRealIp = require('express-real-ip')();

app.use(getRealIp);

app.get('/', function (req, res, next) {
    res.send(req.ip);
    next();
});

app.listen(3000, function() {
    console.log('Listening on port %d', server.address().port);
});

// curl localhost:3000 -H "X-Real-Ip: 87.250.248.98"
// 87.250.248.98
API

express-real-ip(options)

Returns middleware function, that appends header value to X-Forwarded-For header (this is how express figures out req.ip value).

options

headerName - name of header, which contains real ip address (defaults to X-Real-Ip).
License
MIT (c) 2014 Vsevolod Strukchinsky (floatdrop@gmail.com)