Skip to content

Instantly share code, notes, and snippets.

@zedar
Last active August 29, 2015 14:06
Show Gist options
  • Save zedar/82a78162725b438e64cd to your computer and use it in GitHub Desktop.
Save zedar/82a78162725b438e64cd to your computer and use it in GitHub Desktop.
ratpack public address of your server

Ratpack handlers have access to ratpack internal components. Especially:

  • context - implements interface ratpack.handling.Context
  • registry - implements interface ratpack.registry.Registry
  • publicAddress - implements interface ratpack.server.PublicAddress

context and registry variables are accessible without declaration. The other has to be declared as handler parameter.

In order to get public address of ratpack application declare publicAddress variable in your handler. In ratpack.groovy file import:

import ratpack.server.PublicAddress

and then have an access to PublicAddress instance. getAddress method requires ratpack context as parameter.

ratpack {
    get("/api") { PublicAddress publicAddress ->
        log.debug("Server address: ${publicAddress.getAddress(context)}")
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment