Monday, December 21, 2009

Static files with Grails AppEngine plugin

Its been quite a while since my last post, but here is a quick tip:

For my latest project I've decided to use Grails and deploy onto Google AppEngine. There is a nice looking Grails plugin specifically for deploying onto AppEngine (http://www.grails.org/plugin/app-engine). Unfortunately the plugin has a bug which means that static files don't get reloaded when running in development mode. This is a real pain when most of this project is being written in JavaScript - I needed to restart the development web server after every change!

As a workaround I've installed nginx and configured it to serve my static files directly from the file system (so they get reloaded when changed) and proxy any other request to the development web server.

On MacOS this was pretty simple:
  1. Install nginx from MacPorts (sudo port install nginx)
  2. Edit the example config with the following relevant sections:
    location / {
    #root share/nginx/html;
    #index index.html index.htm;
    proxy_pass http://127.0.0.1:8080;
    }

    location ~* ^.+\.(js|css|png|jpg|gif)$ {
    root /path/to/your/application/web-app;
    }