cloudflare-ip-ranges
v2.1.0
Published
Get Cloudflare IPs for use in trust proxy configurations
Downloads
315
Maintainers
Readme
Cloudflare IP ranges
Get Cloudflare IPs for use in trust proxy configurations.
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.
Install
npm install --save cloudflare-ip-ranges
Usage
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.
Directly update trust proxies for an Express app
const cloudflareIPRanges = require('cloudflare-ip-ranges')
updateTrustProxy(app)
setInterval(() => {
updateTrustProxy(app)
}, 1000*60*60*12)
Getting a list of IPs and updating trust proxies manually
Useful if you need to list other proxies alongside the Cloudflare ones.
cloudflareIPRanges.updateIPs()
.then((ips) => {
app.set('trust proxy', ['loopback', ...ips])
})
API
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>
.