Grails access current environment from within config.groovy

configuration, grails

Solution

Try this:

def currentServerUrl = Environment.current.name == 'development' ? devServerUrl : prodServerUrl;

Problem

Using the Grails OAuth plugin requires that an absolute callback URL be provided in Config.groovy. However I have different serverURLs for each environment. Is there a way to get the current environment from inside Config.groovy, here's an example of what I want to do: ``` def devServerUrl = 'http://dev.example.com' def prodServerUrl = 'http://prod.example.com' def currentServerUrl = grailsApplication.metadata.environment == 'development' ? devServerUrl : prodServerUrl; environments { development { grails { serverURL = devServerUrl } } production { grails { serverURL = prodServerUrl } } } oauth { providers { runkeeper { api = RunKeeperApi key = 'key' secret = 'secret' callback = currentServerUrl + '/oauth/runkeeper/callback' } } } ``` Any ideas? Thanks!

Original source