It’s Cloudflare All the Way Down


E

I rewrite my personal website every few years. It’s a chance to learn the hot new technology of the time period, and to revamp the design with one I like more.

In 2012, ejj.io was a few PHP files served with Apache, fronted by Cloudflare. I then rewrote it to be Golang fronted by Cloudflare in 2015.

I attempted to rewrite it a few times, and ended up rewriting it in Express in July of 2018.

Today, ejj.io is written and delivered completely with Cloudflare Workers. I realized while rebuilding my site that Cloudflare is now my website’s entire stack, not just the way the content is delivered.

The source code for this site is available on github.

The site’s routing is handled using Worker Router. It’s a simple express-like (this is very generous) router I whipped up to do routing in workers.

Here’s an example:

var workerrouter = new require('workerrouter')
var app = new workerrouter();

app.post('^/hello/(?<greet>[a-zA-Z]+)', async function(request) {
  return new Response('Hello ' + request.params.greet);
})

The deployment of my site is handled with cf. It’s a simple Cloudflare CLI that I use to upload my static files, deploy my worker, and whatever else I need to do.

I wrote this blog post as markdown, which is read from Workers KV, converted to HTML, and served. You might notice I have some non-markdown blog posts as well. These are legacy posts that I hand wrote in HTML, and didn’t want to spend the time converting to markdown.

I use cf to write static files to the storage namespace that I set up for my blog.

I’ve never rolled out a staging site for my personal blog before, but it was really simple to do with Workers ‘Routes’ feature.

I deploy my staging site at staging.ejj.io instead of ejj.io. It’s deployed as a separate worker script, and each worker script has a separate make target.

It’s not a website without a secure connection. Instead of worrying about TLS myself, this site uses a Cloudflare Dedicated Certificate.

I use dedicated certificates because I am an employee at Cloudflare and wanted to try them out, but Universal SSL for free would work just as well.

For the most part, all domains on Cloudflare must use Cloudflare’s DNS. ejj.io is not an exception, and my nameservers point at carter.ns.cloudflare.com and donna.ns.cloudflare.com.

Cloudflare handles advertising my website’s DNS records around the globe with ANYCAST.

My domain is registered with Cloudflare Registrar. It’s nice to not worry about paying for WHOIS protection as a US resident. Cloudflare automatically redacts my personal information.

Note the “DATA REDACTED” in some of the whois results.

Cloudflare is doing so much for my website that domain registration is hard to fit on the screen.

It’s interesting now that Workers and Registrar exist, I can now use Cloudflare for every part of my website and stop paying DigitalOcean and managing a server.

The entire rewrite of my site using Workers took only about an hour of work to do from scratch. One of the requirements was that it would be easier to write blog posts as markdown, so hopefully I am able to write more often.

Feb 10, 2019

Products You May Like

Leave a Reply

Your email address will not be published. Required fields are marked *