Monday, April 21, 2008

Free Webhosting, Google App Engine style

A week ago, I discussed ways of getting more usage out of the three applications one may create in the trial period. What if the opposite is true, however? What if one has a perfectly good application id left but no idea what to use it for? Well, why not running your static webpage from it? After all, it's free :-)

The smallest app ever

The following app.yaml is a complete App Engine application. Just drop your entire webpage into a subfolder called "static", and it will be served:
application: mysite
version: 1
runtime: python
api_version: 1

handlers:
- url: /(.*)
static_files: static/\1
upload: static/(.*)

What does it do? Well, the regular expression "/(.*)" stands for "every request coming in." The following line instructs the application to look for a static file with the same name in the "static" subfolder. Last but not least, we also tell the application to upload that entire folder as static content into the application.

In other words, for the simplest of all cases, we can turn our webpage into an App Engine application with just a little bit of configuration magic. But wait, there is more:

Leveraging Templates

A lot of App Engine users these days seem to be requesting PHP. There certainly are many good reasons for that, but I kindof wonder if some purposes PHP is used for cannot be easily handled with Django templates. If, for instance, you happen to use PHP simply as a way to not having to copy and paste the same header and footer each and every time, App Engine is the right tool for you.
Take a look at Training Wheels. This site is a simple extension of the app.yaml shown above that serves pages in a slightly more sophisticated manner:
  • requests that do not end with "django" or "djhtml" are served as static content
  • "django/djhtml"-requests are considered Django templates that should be executed
In other words, without having to write a single line of python, one can use the richness of Django templates to stub out common things like headers and footers and have them behave the same way in all web pages. For more details on how it's done, check out the downloads-section of the app.

Serving big files

Right now, there are limitations on the file size an App Engine application may serve. However, it might make sense to outsource certain bigger files to another place, such as Google Sites. The reason for that is simple: quota. Assume that you have a bigger download (like a giant pdf file) that gets accessed many times a day. Why should that have to come out of your quota? Simply create a "file bin" in sites, upload your files there and have them also hosted for free. See this example downloads section built on sites.

Conclusion

An application is a terrible thing to waste. So is free stuff ;-). So, if you are one of the lucky few with an app to spare, consider migrating your homepage. Not only might it save you a few bucks a year, you also can extend it over time with all kinds of dynamic content, based on Google App Engine.

4 comments:

Dom Derrien said...

Thanks for sharing technical tricks on GAE.

I referenced this post in mine describing GAE service: Google App Engine: Free Hosting and Powerful SDK.

Note also your post The darker side of multiplexing, or how to prevent site hijacking is mentioned in my same post;)

Your two articles shows how simple it is to put static webpages on GAE and to prevent that anyone reuse them abusively.

A+, Dom

Triplefox said...

A note for those trying to copy-paste this code(for example myself), additional spaces are required for the lines after "- url: /(.*)", they must have been nuked by the blog engine.

Amey said...

GAE has a limitation of allowing applications to store not more than 10MB of a single large file on it’s server. This may not be a problem for some of the web applications. This is a serious issue for many web applications which assume sufficiently large underlying storage,
Many like me have tried and realized the same as in this blog


http://bygsoft.wordpress.com/2010/01/09/cloudy-combo-google-app-engine-and-amazon-s3-combo-pack/

The App Engine Fan said...

> GAE has a limitation of allowing applications to store not more than 10MB of a single large file on it’s server.

Correct, thanks for pointing that out. In the article, I am mentioning file size limitations and recommend an alternate location for those files (in the example, I am using sites, but it could basically be anything)