get-request-ip
A small, configurable module to get a request's IP address.
Code Example
const getRequestIP = ; // get the ip address, respecting the following headers if they// are set:// x-client-ip// x-forwarded-for// x-real-ip// x-cluster-client-ip// x-forwarded// forwarded-for// fowarded server; // or you can configure only the headers you want to respectserver; // or you can ignore all headers and only try to read from the request's connectionserver;
Motivation
There are a handful of implementations out there for getting the IP address that a request came from. I haven't seen one that is both configurable and tested. This module aims to fulfill both those requirements.
Installation
npm install --save get-request-ip
Options Reference
headers
An array of headers to trust for determining the source IP. Default:
'x-client-ip' 'x-forwarded-for' 'x-real-ip' 'x-cluster-client-ip' 'x-forwarded' 'forwarded-for' 'fowarded'
Be wary of this setting. It is very liberal by default, which could allow a malicious actor to spoof an IP . This liberal setup assumes that you have set up your app behind a sane proxy. If you'd like to lock this down, it's an easy configuration change:
server;
Tests
npm run test
Contributing
Contributions are encouraged and appreciated. To make the process as quick and painless as possible for everyone involved, here's a checklist that will make a pull request easily accepted:
- Implement your new feature or bugfix
- Add or update tests to ensure coverage
- Ensure your code passes jshint according to the jshintConfig in package.json
- Ensure your code is formatted according to the .jsbeautifyrc
- Submit
License
MIT