Dónal
Dónal

Reputation: 187499

HTTPS Grails application URL

My Grails app runs over HTTPS and in Config.groovy I've set:

environments {
    development {
        grails.serverURL = "https://localhost:8443/foo"
    }
}

When I execute grails run-app to start the app in dev mode, the last message printed on the console is:

Server running. Browse to http://localhost:8082/foo

If I accidentally click on this URL to access the application, I get various errors due to the same-origin security policy (because https://localhost:8443 is a different host to http://localhost:8082).

Why is Grails prompting me to access my app via http://localhost:8082/foo when I've set grails.serverURL = "https://localhost:8443/foo"

Update

I changed the startup command to grails run-app -https and the last message printed on the console is now:

Server running. Browse to http://localhost:8082/foo or https://localhost:8443/foo

Why am I given the option of either HTTP or HTTPS, rather than just the latter? Also, I get this exception during startup:

http11.Http11Protocol Failed to initialize end point associated with ProtocolHandler ["http-bio-8443"]
java.net.BindException: Address already in use <null>:8443
    at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:407)

I've checked if port 8443 is in use before I run this command (it isn't), but the server seems to startup despite this exception, so this is not a major concern.

Upvotes: 1

Views: 6142

Answers (3)

Abh Swar
Abh Swar

Reputation: 87

You can set the ssl port you want to run you application on via https in BuildConfig.groovy. You can add the following to your BuildConfig.groovy

//You can specify another port here to get rid of your startup exception grails.server.port.https="8443"
grails.server.host="localhost"

Then try grails run-app -https and you should be able to run your app on the ssl port you defined or the default 8080 port

Upvotes: 1

Joshua Moore
Joshua Moore

Reputation: 24776

You need to use the --https parameter to run-app for Grails to respond to HTTPS and HTTP in development mode. At least according to the documentation.

Try using

grails run-app --https

Further more, the grails.serverURL is typically used by taglibs and plugins, and not the launching process as far as I can tell.

Upvotes: 1

Sam Farmer
Sam Farmer

Reputation: 4118

Replace grails.serverURL with the code below.

Its possible to set the port with the following system properties:

grails.server.port = 8082

That should work for both http and https. To configure for just one:

grails.server.port.https = 8082

Upvotes: 3

Related Questions