Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cccpurge

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cccpurge

Choo Cloudflare Cache Purge – purge all routes served by choo app

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-60.87%
Maintainers
2
Weekly downloads
 
Created
Source

cccpurge

npm version build status downloads js-standard-style

Purge Cloudflare cache of all routes served by a Choo app. This is usefull when enabling cache for all content and you later need to purge the cache for html pages due to updated content or when publishing a new version of your app. E.g. one could use this as part of a webhook that is triggerd by changes made to a CMS or as part of a deploy script.

Usage

You'll need to get your Cloudflare Zone ID, it's on the dashboard overview when signing into your Cloudflare account. Just below that is a link to get your API key.

#!/usr/bin/env node

var cccpurge = require('cccpurge')

cccpurge(require('./index'), {
  root: 'https://www.my-blog.com',
  email: 'foo@my-blog.com',
  zone: '7sef78we7hwhefw3hri3uhriu32rwehf',
  key: '0046ffew5f560675hny5765r7gre6005reg05'
}, console.log)

Dynamic routes

Dynamics routes (wildcards/params) are supported out of the box but you'll have to supply a function that resolves them to actual urls. The resolve function is given the route (e.g. /posts/:post) and a callback. How you resolve /posts/:post to /post/my-first-post is completely up to you. Here's an example using Prismic.

#!/usr/bin/env node

var Prismic = require('prismic-javascript')
var cccpurge = require('cccpurge')
var app = require('./index')
var opts = {
  resolve: resolve,
  root: 'https://www.my-blog.com',
  email: 'foo@my-blog.com',
  zone: '7sef78we7hwhefw3hri3uhriu32rwehf',
  key: '0046ffew5f560675hny5765r7gre6005reg05'
}

cccpurge(app, opts, done)

function done (err, response) {
  if (err) console.error(err)
  else console.log('Cache purged!')
  process.exit(0)
}

function resolve (route, done) {
  // only bother purging posts
  if (route !== '/posts/:post') return done(null)

  // fetch posts from prismic api
  Prismic.getApi('https://my-site.cdn.prismic.io/api/v2')).then(function (api) {
    return api.query(
      Prismic.Predicates.at('document.type', 'blog-post')
    ).then(function (response) {
      done(null, response.results.map((post) => `/posts/${post.uid}`))
    })
  }).catch(done)
}

Limit

Cloudinary has a limit of maximum 30 urls per call to the purge endpoint. We respect that limit but it can be overridden by setting opts.limit to any number. Requests are made in parallel with a miximum of limit urls per request.

Keywords

FAQs

Package last updated on 20 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc