Monday, May 20, 2013

Making my webserver run on App Engine

So I had my two python scripts that were serving my tax visualization webpage (a JSON Server on localhost:9888 and a trivial server for files on disk (like the HTML page) on localhost:9889). How to make that available on the web?

Of course I could just put my static pages on some free web hosting place, but that misses the point in that I'd like to maintain my own JSON server. So my friends at work suggested using EC3 (Amazon)  or App Engine (Google). Since EC3 seems to possess a 1-year expiration time of the freebie quota, I decided to go for GAE.

GAE provides a development kit that allows for local development and contains some upload scripts. But I wanted to do everything on my Chromebook Pixel which does not have a real shell (can't enable developer mode because it's a corporate laptop). So I looked around and came across codenvy.com, formerly eXo Cloud IDE, a free service that offers online coding and integration with many services, amongst which GAE. Cloud 9, another popular online dev platform, does not seem to offer that integration.

Here are the things I needed to adapt in order to make it work:

  • Write a configuration file (app.yaml) that specifies the handlers, i.e. what to do when a certain URL is requested. In my application /json.* URLs are handled by a python script whereas all other URLs are just served.
  • Adapt my python script to use the webapp2 server library instead of the native Python web server modules.
There are a lot of small details that can go wrong with either of them, but in 7-8 hours' time I managed to make it work.

The final result is at
http://swisstaxvisualization.appspot.com/

No comments:

Post a Comment