Skip to content

Commit

Permalink
docs: Demonstrate ES6 usage
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Node 8 no longer supported
  • Loading branch information
Nick Hammond authored and nhammond101 committed Feb 15, 2023
1 parent 704288a commit 426dd07
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,49 @@ _V2 drops support for Node v8_

Requires node `10` or newer, but only [LTS](https://nodejs.org/en/about/releases/) are officially supported .

npm install --save cloudfront-ip-ranges
```shell
npm install --save cloudfront-ip-ranges
```

## Usage

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.

#### Directly update trust proxies for an Express app
### Directly update trust proxies for an Express app

const cfIPranges = require('cloudfront-ip-ranges')
```javascript
const cfIPranges = require('cloudfront-ip-ranges');

cfIPranges.updateTrustProxy(app)
cfIPranges.updateTrustProxy(app);

setInterval(() => {
cfIPranges.updateTrustProxy(app)
}, 1000*60*60*12)
setInterval(() => {
cfIPranges.updateTrustProxy(app);
}, 1000 * 60 * 60 * 12);
```

#### Getting a list of IPs and updating trust proxies manually
### Getting a list of IPs and updating trust proxies manually

Useful if you need to list other proxies alongside the Cloudfront ones.

const cfIPranges = require('cloudfront-ip-ranges')
```javascript
const cfIPranges = require('cloudfront-ip-ranges');

cfIPranges.updateIPs()
.then((ips) => {
app.set('trust proxy', ['loopback', ...ips])
})
cfIPranges.updateIPs().then(ips => {
app.set('trust proxy', ['loopback', ...ips]);
});
```

### ES6

You can import the module like so:

```javascript
import {CloudfrontService} from "cloudfront-ip-ranges";

new CloudfrontService().getIpRange().then( (ips)=> ...);
```

## API

Expand Down

0 comments on commit 426dd07

Please sign in to comment.