Skip to content

Instantly share code, notes, and snippets.

@danhyun
Created August 20, 2014 14:06
Show Gist options
  • Save danhyun/83475c02aa53ebd19a08 to your computer and use it in GitHub Desktop.
Save danhyun/83475c02aa53ebd19a08 to your computer and use it in GitHub Desktop.
Setting base url
class BaseUrlHandler implements Handler {
void handle(Context context) throws Exception {
context.with {
def headers = request.headers
def scheme = headers.contains('X-Forwarded-Proto') ? headers.get('X-Forwarded-Proto') : 'http'
def domain = headers.get('Host') ?: headers.get('host')
def baseUrl = "${scheme}://${domain}" as String
request.register(BaseUrl, new BaseUrl(baseUrl))
next()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment