Get Cloudflare IPs for use in trust proxy configurations. You might also be interested in Cloudflare authenticated origin pulls.
This package will be updated if Cloudflare ever decides to change the endpoints for retrieving current IPs. We will most likely never see a breaking change for this package.
Requires node 7
or newer.
npm install --save cloudflare-ip-ranges
For use in an Express environment please see Express documentation on trust proxies.
It is recommended to use setInterval
for updating the IP list periodically.
const cfIPranges = require('cloudflare-ip-ranges')
cfIPranges.updateTrustProxy(app)
setInterval(() => {
cfIPranges.updateTrustProxy(app)
}, 1000*60*60*12)
Useful if you need to list other proxies alongside the Cloudflare ones.
const cfIPranges = require('cloudflare-ip-ranges')
cfIPranges.updateIPs()
.then((ips) => {
app.set('trust proxy', ['loopback', ...ips])
})
Method | Info |
---|---|
updateIPs | By default returns Promise<string[]> . By specifying { versioned: true } as an argument you get an object that contains V4 and V6 separately (Promise<{ V4: string[], V6: string[] }> ). |
updateTrustProxy | Takes an Express app instance as an argument. Returns Promise<void> . |
Version | Release notes |
---|---|
2.1.0 | Adds the possibility of directly updating trust proxies for an Express app using updateTrustProxy . |
2.0.0 | Change default behavior of updateIPs into returning a flat list of IPs. |
1.0.1 | Add info to documentation about using setInterval for keeping the IPs fresh. |
1.0.0 | Initial release. |