Static Website On Google App Engine

September 13, 2017

*This article will describe how I hosted my static website and blog (this website) on Google App Engine (Standard). Some familiarity with nix tools and programming is assumed.

Pretext

Hosting stuff with traditional shared hosts is not a pleasant experience. They’re usually slow, oversold and more or less stuck in 2006 in terms of developer experience. It’s 2017 and I wasn’t going to subject myself to the torture that is uploading your files through FTP client. So I had two very straightforward criteria to host my website:

Simple: The process to deploy new version of website should be painless. It shouldn’t take more than one command.

Free: I like free stuff and I can’t lie.

Looking around, I found GAE’s (Google App Engine) official tutorial that shows you how to host a static website. The entire process boils down to: a) install their SDK (Software Development Kit) and b) populate a file called app.yaml to tell appengine what to do. Deploying the application is also as simple as running gcloud app deploy. First requirement satisfied.

The maximum rate of 56MB/minute is fine for mostly text website with low traffic but if you are hosting any sort of image, it is a good idea to configure your website behind CloudFlare.

That is good enough to run my site for free forever. Second requirement satisfied.

With the requirements sorted I followed the official tutorial and had my website up in no time. At this point, I have a single html file inside the www folder. This folder is going to be my web root.

.
├── app.yaml
└── www
└── index.html

The Roadblock

While this setup worked pretty well for a single page static website, it quickly became unusable when I tried hosting a blog. Jekyll generates pretty URL by default which means each post is inside it’s own several levels deep directory (/blog/yyyy/mm/dd/post-title/index.html) which was difficult to configure using the configuration format for GAE. With blog included, the project has many directories than before:

Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems. - Jamie Zawinski

I think now I know what Jamie Zawinski was referring to.

The Solution

Luckily Google App Engine, as name implies, is a full blown app platform. If I can’t configure GAE to work exactly the way I want it to, logic dictates that I write my own.

GAE supports several programming languages including golang, python and nodejs among others. golang has the best primitives for writing a web server so it is a natural choice. Here is a minimal web server I wrote to serve static directory www.