1.0.1 • Published 11 years ago
addr v1.0.1
addr
Get the remote address of a request, with reverse-proxy support
Usage
$ npm install addraddr(req, [proxies])
req: anhttp.ServerRequestobject.proxes: an array of IP addresses of trusted proxies. If specified and the request doesn't come from one of these addresses, theX-Forwarded-Forheader will not be honored.- Returns: Remote IP address of the request, taken from the
X-Forwarded-Forheader if it exists and the request is coming from a trusted proxy.
Example
var addr = require('addr')
, http = require('http')
, port = 3000
, proxies = ['127.0.0.1']
;
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'application/json'});
res.write(JSON.stringify({addr: addr(req, proxies)}));
res.end();
}).listen(port, function() {
console.log('test server running on port ' + port);
});License
MIT
