Launching a grails-app through Intelli-J with root set to localhost:8080/ instead of localhost:8080/app, or modifying createLink?
Asked Answered
W

1

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?

Weil answered 14/2, 2011 at 6:45 Comment(0)
A
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 = "/"
Aurita answered 14/2, 2011 at 7:9 Comment(8)
I should have checked this first. I bet I even configured this for production v_v.Weil
@Stefan: I had the same problem before. Hope this helpPomology
This isn't working. 'createLink' still generates /app/main/whatever, when it needs to generate /main/whatever.Weil
@Stefan: how did you change it? Have you tried "grails clean"?Pomology
Yes, I have. I have one Url Mapping: " "/"(controller:"main"). Even if I specify grails.serverUrl = "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.Weil
@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.Pomology
That's what I was missing. You might also be interested in answering #5000346 :PWeil
@Stefan: thanks, but looks like I'm a little late. That's a perfect question & answer.Pomology

© 2022 - 2024 — McMap. All rights reserved.