Giter Club home page Giter Club logo

mfydev / ghost-bunnycdn-cache-clearer Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 12 KB

Cloudflare Worker that automatically purges BunnyCDN pull zone cache and cleans up Perma-Cache folders upon receiving Ghost CMS webhooks, optimizing storage usage and reducing costs.

License: MIT License

JavaScript 100.00%
bunnycdn bunnycdn-adapter bunnycdn-api bunnycdn-storage cloudflare cloudflare-worker cloudflare-workers ghost ghost-blog ghost-cms

ghost-bunnycdn-cache-clearer's Introduction

Ghost BunnyCDN Cache Purger

Motivation

BunnyCDN's Perma-Cache feature retains files in a new directory structure after a full pull zone purge. While this can improve performance in some scenarios, it may lead to unnecessary storage costs over time. This webhook-based solution automates the clearing of old cache folders, preventing excessive space usage and associated expenses.

Features

  • Automatically purges BunnyCDN pull zone cache upon receiving a webhook from Ghost CMS
  • Clears old Perma-Cache folders to prevent unnecessary storage usage
  • Verifies webhook signatures for security
  • Logs detailed information for easy debugging and monitoring
  • Designed to run as a Cloudflare Worker for scalability and low latency

Installation

  1. Clone this repository:

    git clone https://github.com/yourusername/bunnycdn-cache-purger.git
    
  2. Set up a Cloudflare Worker:

    • Log in to your Cloudflare account and navigate to the Workers section
    • Create a new Worker and paste the contents of index.js into the script editor
  3. Set up environment variables in your Cloudflare Worker:

    • GHOST_WEBHOOK_SECRET: Your Ghost webhook secret
    • BUNNY_PULLZONE_ID: Your BunnyCDN pull zone ID
    • BUNNY_API_KEY: Your BunnyCDN account API key
    • BUNNY_STORAGE_ZONE_HOSTNAME: Your storage zone hostname (e.g., "ny.storage.bunnycdn.com")
    • BUNNY_STORAGE_ZONE_NAME: Your storage zone name
    • BUNNY_STORAGE_ZONE_PASSWORD: Your storage zone password
  4. Configure your Ghost CMS to send webhooks to your Cloudflare Worker URL when content is published or updated

Code Overview

The main components of the script are:

  • handleRequest: The main function that processes incoming requests
  • verifySignature: Verifies the Ghost webhook signature for security
  • cleanupPermaCacheFolders: Clears old Perma-Cache folders in BunnyCDN storage

The script listens for POST requests to the /purge-full-cache endpoint. When a valid request is received, it:

  1. Verifies the Ghost webhook signature
  2. Purges the BunnyCDN pull zone cache
  3. Cleans up old Perma-Cache folders

Detailed logs are provided at each step for easy monitoring and debugging.

License

This project is licensed under the MIT License.

ghost-bunnycdn-cache-clearer's People

Contributors

mfydev avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.