1
votes

For a variety of reasons, I need programatic JavaScript access the the hostname or IP address of the Worklight server from the client code.

For example: - I want to pull scripts and resources from the same host as the Worklight server - I have an out-of-band service on the Worklight host and I want to connect to it

@IdanAdar has said that the address does not exist. I've search the WL object and cannot find it either. See Can we get the app version and IP address info using worklight api?.

Note that document.location.hostname is null when running as a native app.

2

2 Answers

1
votes

My current workaround is to set the IP Address / hostname as a global variable in my top-level html file. This is not ideal because it causes my sourcecode to have to vary by implementation.

Worklight already has this value externalized in the application-descriptor.xml

The server side API has this exposed in WL.Server.configuration["local.IPAddress"]. I think the client should expose an API similar to this as well.

0
votes

Although not the best option you can develop an adapter that returns the WL.Server.configuration["local.IPAddress"] if available, also could be possible to acces to the IP through the http request.

Is it possible to access to the HTTPRequest in the worklight adapter implementation?

I'm not sure if you can invoke adapters before wlCommonInit, if you can not and you need the ip before the common init then this approach is useless.