2.1.0 • Published 5 years ago

cloudflare-ip-ranges v2.1.0

Weekly downloads
23
License
MIT
Repository
github
Last release
5 years ago

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

MethodInfo
updateIPsBy 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[] }>).
updateTrustProxyTakes an Express app instance as an argument. Returns Promise<void>.