![]() | Name | Last modified | Size | Description |
---|---|---|---|---|
![]() | Parent Directory | - | ||
![]() | dist/ | 2 years ago | - | |
![]() | LICENSE.md | 39 years ago | 1.1K | 7375cab EXHIBTION: fix overflow ellipsis cutoff [كارل مبارك] |
![]() | package.json | 2 years ago | 2.5K | 7375cab EXHIBTION: fix overflow ellipsis cutoff [كارل مبارك] |
![]() | README.md | 39 years ago | 3.1K | f12eb36 documentaiton updates [كارل مبارك] |
![]() | CHANGELOG.md | 39 years ago | 7.1K |
A tiny Node.js module for retrieving a request's IP address.
npm install request-ip --save
const requestIp = require('request-ip');
// inside middleware handler
const ipMiddleware = function(req, res, next) {
const clientIp = requestIp.getClientIp(req);
next();
};
// on localhost you'll see 127.0.0.1 if you're using IPv4
// or ::1, ::ffff:127.0.0.1 if you're using IPv6
const requestIp = require('request-ip');
app.use(requestIp.mw())
app.use(function(req, res) {
const ip = req.clientIp;
res.end(ip);
});
To see a full working code for the middleware, check out the examples folder.
The connect-middleware also supports retrieving the ip address under a custom attribute name, which also works as a container for any future settings.
It looks for specific headers in the request and falls back to some defaults if they do not exist.
The user ip is determined by the following order:
X-Client-IP
X-Forwarded-For
(Header may return multiple IP addresses in the format: "client IP, proxy 1 IP, proxy 2 IP", so we take the the first one.)CF-Connecting-IP
(Cloudflare)Fastly-Client-Ip
(Fastly CDN and Firebase hosting header when forwared to a cloud function)True-Client-Ip
(Akamai and Cloudflare)X-Real-IP
(Nginx proxy/FastCGI)X-Cluster-Client-IP
(Rackspace LB, Riverbed Stingray)X-Forwarded
, Forwarded-For
and Forwarded
(Variations of #2)req.connection.remoteAddress
req.socket.remoteAddress
req.connection.socket.remoteAddress
req.info.remoteAddress
If an IP address cannot be found, it will return null
.
Make sure you have the necessary dev dependencies needed to run the tests:
npm install
Run the integration tests
npm test
See the wonderful changelog
To easily generate a new changelog, install github-changelog-generator then run npm run changelog
.
CF-Connecting-IP
, True-Client-IP
, and ES6 support.The MIT License (MIT) - 2018