Expand my Community achievements bar.

Configure js variables based on environments

Avatar

Level 5

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? 

3 Replies

Avatar

Employee Advisor

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. 

Avatar

Level 10

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

Avatar

Level 10

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