0
votes

My question is: can I change worklight server url dynamically (with javascript) ? tnks for the answers.


Thank you for the answers! this is my code:

    function loadXMLDoc(dname)
    {
        if (window.XMLHttpRequest)
        {
            xhttp=new XMLHttpRequest();
        }
        else
        {
            xhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhttp.open("GET",dname,false);
        xhttp.send();
        return xhttp.responseXML;
    }

    function wlCommonInit(){






        xmlDoc=loadXMLDoc("/BadgeSYSmProj/apps/BadgeSysApp/application-descriptor.xml");


        x=xmlDoc.getElementsByTagName("worklightServerRootURL")[0].childNodes[0];
        x.nodeValue="http:\\NEW URL.html";

        document.write(x.nodeValue);

    ...
    ...

    

but there is an fault:

Failed to load resource: the server responded with a status of 404 (ProxyServlet: /BadgeSYSmProj/apps/BadgeSysApp/application-descriptor.xml) http**://localhost:8080/apps/services/preview/BadgeSysApp/common/0/default/js/BadgeSysApp.js Uncaught TypeError: Cannot call method 'getElementsByTagName' of null

2
if the server url changes, the application should automatically connect to itAntonio Martines
That would strike me as a strange configuration for a production environment when time comes...?Idan Adar

2 Answers

1
votes

No, you cannot. WL Server URL is hardcoded in your application when you build it. It is taken from application-descriptor.xml file (the worklightServerRootURL element) and injected into each environment.

0
votes

Yes, you can edit application-descriptor.xml and create a new build every-time you want to change the URL. Even better would be a build script that generates a .wlapp package depending on the URL mentioned in worklight.properties.{env}. That would help in promoting Worklight deployments across environments