Created
August 20, 2014 14:06
-
-
Save danhyun/83475c02aa53ebd19a08 to your computer and use it in GitHub Desktop.
Setting base url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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