2

Is there a way to launch an application through Intelli-J so that it makes localhost:8080/ the root of the application? The problem I'm having is that AJAX urls that work locally don't work in production, and createLink(action:"ajaxUpdate") seems to create references to /app/ajaxUpdate, which works locally but not in production.

Is there a way to fix createLink to work in both locations? I thought perhaps I could just use UrlMappings to make all the ajax calls pretty and just refer to /ajaxUpdate, but that doesn't work because of how the grails application is deployed within Intelli-J.

How do I fix this?

Stefan Kendall
  • 66,414
  • 68
  • 253
  • 406

1 Answers1

6

About your problem, in grails-app/conf/Config.groovy you can specify the server URL, like this:

environments {
    production {

        grails.serverURL = "http://localhost/"  // Specify the "root" of your link
        ....
    }

    development {
        grails.serverURL = "http://localhost:8080/${appName}"
        ...
    }
    ...
}

Then the createLink method should be fine. As I know, it's about Grails config, not relate to IntelliJ.

EDIT: It seems that I missed some information: to make the createLink start at "http://localhost/", it's necessary to add another line into Config.groovy:

grails.app.context = "/"
Hoàng Long
  • 10,746
  • 20
  • 75
  • 124
  • I should have checked this first. I bet I even configured this for production v_v. – Stefan Kendall Feb 14 '11 at 14:23
  • @Stefan: I had the same problem before. Hope this help – Hoàng Long Feb 15 '11 at 03:22
  • This isn't working. 'createLink' still generates /app/main/whatever, when it needs to generate /main/whatever. – Stefan Kendall Feb 15 '11 at 03:40
  • @Stefan: how did you change it? Have you tried "grails clean"? – Hoàng Long Feb 15 '11 at 03:47
  • 1
    Yes, I have. I have one Url Mapping: " `"/"(controller:"main")`. Even if I specify grails.serverUrl = "http://localhost:8080/" in the development/test environment, the application is still available on :8080/app, rather than :8080. Because of this, urls that work in development don't work in production. – Stefan Kendall Feb 15 '11 at 03:50
  • @Stefan: it seems I missed some details: add this to your Config.groovy: grails.app.context = "/" . I have tested it out in Development,it's ok. – Hoàng Long Feb 15 '11 at 04:14
  • That's what I was missing. You might also be interested in answering http://stackoverflow.com/questions/4999846/grails-run-app-on-localhost8080-instead-of-8080-appname :P – Stefan Kendall Feb 15 '11 at 04:27
  • @Stefan: thanks, but looks like I'm a little late. That's a perfect question & answer. – Hoàng Long Feb 15 '11 at 04:51