0

I have added an externalized properties file in Config.groovy file. Such as:

grails.config.locations << "file:app-test-config.properties"

And this how my externalized properties file app-test-config.properties look like:

SERVER_IP_ADDRESS = 123.456.789.0
SERVER_PORT= 1234

I am using AngularJs framework and I have a javascript file in assets directory. Now, I want to access the server IP and Port in that javascript file.

How this can be possible? Is there any way to use Holder or grailsApplication in javascript file to read attributes from externalized properties file?

Bilal Ahmed Yaseen
  • 2,506
  • 2
  • 23
  • 48

1 Answers1

0

You can create a controller action as following:

class JavaScriptController {

  def grailsApplication
  def config() {
    String config = "${grailsApplication.config.flatten() as JSON}"
    String content = "config= ${config}"   
    render contentType: 'text/javascript', text: content
  }

}

Haven't tested the above code but the idea is to push a javascript file which will contain all the config as javascript object. You can apply caching/cloudfront to this response so that your server don't get many requests.

Uday
  • 619
  • 3
  • 7