Git Product home page Git Product logo

cloudflare-pages-custom-preview-domain's Introduction

cloudflare pages custom domain for preview deployments

you want a custom subdomain for your cloudflare pages preview deployment? read on.

this is just a quick n dirty project, let's aim to explain things a bit better and make deployment easier.

you'll create a Worker which calls the Cloudflare API from time to time (defined in the cron pattern) to retrieve the current domain of your latest preview build in Cloudflare Pages. This URL is stored in Cloudflare KV. The Worker will fetch the Cloudflare Pages site then when you hit the configured route.

  1. get your global api key (unfortunately scoped api tokens are not available for pages yet)
  2. create a new cloudflare worker
  3. go to worker settings and add the following environment variables
environment name value encrypt it?
accountId your couldflare account id yes
apiKey cloudflare api key yes
email cloudflare email address yes
projectName cloudflare pages project NAME no
  1. create a Cloudflare KV namespace (you can do this in the Workers Dashboard)
  2. add one key to the namespace already. use route for the key name and the route you want to use for this worker in the value field, something like that:
key value
route https://subdomain.example.com
  1. add the Namespace to your Worker (open the Worker > Settings > Variables > KV Namespace Bindings)
  2. create a cron trigger to execute every hour
  3. open the cloudflare worker editor and paste the contents of the index.js file in this repo in there.
  4. assign a route in the Cloudflare Dashboard to match your Worker, like so:
subdomain.example.com/* => your-worker

cloudflare-pages-custom-preview-domain's People

Contributors

pew avatar

Stargazers

 avatar  avatar  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.