cloudflare-ip-ranges
Version:
Get Cloudflare IPs for use in trust proxy configurations
49 lines (31 loc) • 1.73 kB
Markdown



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.
<p align="center">
<img width="460" src="https://github.com/sampsakuronen/cloudflare-ip-ranges/raw/master/README-image.png?raw=true">
</p>
npm install --save cloudflare-ip-ranges
For use in an Express environment please see [Express documentation on trust proxies](https://expressjs.com/en/guide/behind-proxies.html).
It is recommended to use `setInterval` for updating the IP list periodically.
const cloudflareIPRanges = require('cloudflare-ip-ranges')
updateTrustProxy(app)
setInterval(() => {
updateTrustProxy(app)
}, 1000*60*60*12)
Useful if you need to list other proxies alongside the Cloudflare ones.
cloudflareIPRanges.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>`.