Archief

Dev

Hosting static files on Google App Engine (GAE)

I’m currently working on an app for the new FirefoxOS phone’s hitting the market. A small html/js/css only app that you can run offline and controls your Philips Hue lightbulbs. Who wouldn’t want a $60 dollar phone to control your $200 lightbulbs? My point exactly.

So I have a really lightweight app, that I want hosted. And as I’m doing nearly everything with Google App Engine hosting these days, I want the html/js/css files hosted there.

The easiest way, I found, was to create a Python project. You’ll only need one extra file on top of the static files you have, and put all your files in a subdirectory of the project (say “static_files”). The file is called app.yaml and has something like the following content:

application: firefoxos-hue
version: 1-0                #no . characters allowed :(
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /                         # redirect the homepage to index.html
  static_files: static_files/index.html
  upload: static_files/index.html
- url: /(.*)                     # serve all other files as if they were in the root
  static_files: static_files/\1
  upload: static_files/(.*)

The top block is some metadata about the project, below that the URL handlers. One handler serves index.html when users access the homepage. The second serves all static files from the static_files directory directly to users.

Now you can use the Google App Engine Launcher to import this directory, run it locally, or deploy it as an appengine project.

#google app engine #GAE #hosting