cloudflare-ip-ranges

2.1.0 • Public • Published

Cloudflare IP ranges

npm npm Travis (.org)

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>.

Package Sidebar

Install

npm i cloudflare-ip-ranges

Weekly Downloads

158

Version

2.1.0

License

MIT

Unpacked Size

143 kB

Total Files

8

Last publish

Collaborators

  • sampsakuronen