从Worklight客户端代码中检测Worklight Server主机名/ IP地址 [英] Detect Worklight Server Hostname/IP Address from Worklight Client code

查看:147
本文介绍了从Worklight客户端代码中检测Worklight Server主机名/ IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于各种原因,我需要编程JavaScript从客户端代码访问Worklight服务器的主机名或IP地址。

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

例如:
- 我想从与Worklight服务器相同的主机中提取脚本和资源
- 我没有 - Worklight主机上的乐队服务,我想连接到它

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已经说过该地址不存在。我搜索了WL对象,也找不到它。请参阅我们能否获得该应用使用worklight api的版本和IP地址信息

@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?.

请注意,作为本机应用程序运行时,document.location.hostname为null。

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

推荐答案

我目前的解决方法是在我的顶级html文件中将IP地址/主机名设置为全局变量。这并不理想,因为它导致我的源代码必须根据实现而变化。

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已经在application-descriptor.xml中外化了这个值

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

服务器端API暴露了这个在WL.Server.configuration [local.IPAddress]中。我认为客户端也应该公开类似于此的API。

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.

这篇关于从Worklight客户端代码中检测Worklight Server主机名/ IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆