Wednesday, June 24, 2009

Run grails-app on the root context

USECASE: You want to run your shiny grails killer-app using the jetty server on port 80 and using the root context. Running it on port 80 is covered by providing the grails run-app command with the desired port but your app will still run on http://localhost:80/killer-app. To run it on the root context, you can do:
grails -Dserver.port=80 -Duse.root.context.path=true run-app
but first, you have to modify _GrailsRun.groovy and change an existing method to this:
private runInline(scheme, host, httpPort, httpsPort) {
    EmbeddableServerFactory serverFactory = loadServerFactory()    
    def useRootContextPath = System.getProperty("use.root.context.path")
    if(useRootContextPath)
        serverContextPath = '/'
    grailsServer = serverFactory.createInline("${basedir}/web-app", webXmlFile.absolutePath, serverContextPath, classLoader)
    runServer server: grailsServer, host:host, httpPort: httpPort, httpsPort: httpsPort, scheme:scheme
    startPluginScanner()
}
You can find _GrailsRun.groovy in $GRAILS_HOME/scripts

WARNING: THERE ARE SERIOUS PENALTIES FOR ROLLING OUT YOUR APP THIS WAY

The code seems trivial but I'll submit it anyway to the grails dev team for inclusion. Did it work for you? You are welcome to post your comments/questions or better yet, link to this post, blog about it and tell all your friends who might find this post useful.

1 comment:

  1. There's no need to edit any scripts - this is a maintenance problem since you'll need to keep editing scripts each time you upgrade. Just put

    app.context=/

    in your application.properties

    ReplyDelete