@financial-times/n-fastly-purger
v4.1.0
Published
Lightweight Fastly purger
Downloads
146
Maintainers
Keywords
Readme
n-fastly-purger
Lightweight, asynchronous Fastly purger.
npm i -P @financial-times/n-fastly-purger
Usage
import FastlyPurger from '@financial-times/n-fastly-purger';
const Fastly = new FastlyPurger({
serviceId: 'fastlyServiceId',
fastlyKey: 'fastlyAPIKey',
timeout: 1000, // optional
agent: new Agent({ keepAlive: true }), // optional; https agent
silentMode: true, // optional; defaults to false
loggerFn: sandbox.stub(), // optional
logLevel: 'all' // optional; defaults to 'errors'
});
Options
Silent mode
silentMode: true
: silent failure on purge error and boolean responsessilentMode: false
: throw errors for failed purges; return JSON response from Fastly (status: ok and purge ID)
Logging
logLevel: 'errors'
: only log purge errors (default)logLevel: 'all'
: log successful purges and purge errors
Logger function
A function to output logs; e.g.:
import logger from '@financial-times/n-logger';
// or n-serverless-logger
const Fastly = new FastlyPurger({ ...
loggerFn: logger.error
});
Methods
Fastly.purgeKey('my-surrogate-key'); // purge a single key
Fastly.purgeKeys(['key-1', 'key-2']); // purge multiple surrogate keys
Fastly.purgeAll(); // purge the entire service
Fastly.purgeUrl('https://foo.com/bar'); // purge a single URL