Configure js variables based on environments | Community
Skip to main content
Level 4
Jul 22, 2016 7:29 PM UTC

Configure js variables based on environments

So we've a global javascript but that script has certain URL's specific to environments. What's the best practice to have different URL's configured based on environment.

 

Does anyone have good examples how to do this? 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

edubey
Level 10
Jul 24, 2016 8:55 AM UTC

Hi,

1. Have all these configurations in OSGI config Mgr

2. Create a OSGI service to populate these on page load in <head></head> section page in script tag,

3. Now you can directly read these global url from anywhere in page

This is one of the good, easy way to have environment specific URL in JS

Translate
Kunal_Gaba_
New Participant
Jul 23, 2016 4:16 PM UTC

I would suggest to configure the URLs in run mode specific OSGI configuration nodes. And then you can read those variables in the page head.jsp and render them as global variables inside the <script> tag.  The JS file can simply use these variables to fetch the URLs value. 

Translate
smacdonald2008
Level 10
Jul 23, 2016 11:19 PM UTC

Agree - define your values in OSGi config and retrieve them and use them in a JS function.

Translate