【问题标题】:Detect Worklight Server Hostname/IP Address from Worklight Client code从 Worklight Client 代码中检测 Worklight Server 主机名/IP 地址
【发布时间】:2013-05-27 19:14:05
【问题描述】:

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

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

@IdanAdar 说该地址不存在。我搜索了 WL 对象,也找不到它。见Can we get the app version and IP address info using worklight api?

请注意,作为原生应用运行时,document.location.hostname 为 null。

【问题讨论】:

    标签: ibm-mobilefirst


    【解决方案1】:

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

    Worklight 已经在 application-descriptor.xml 中外部化了这个值

    服务器端 API 在 WL.Server.configuration["local.IPAddress"] 中公开了这一点。我认为客户端也应该公开类似的 API。

    【讨论】:

      【解决方案2】:

      虽然不是最好的选择,但您可以开发一个返回 WL.Server.configuration["local.IPAddress"] 的适配器(如果可用),也可以通过 http 请求访问 IP。

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

      我不确定你是否可以在 wlCommonInit 之前调用适配器,如果你不能并且你需要在公共 init 之前的 ip,那么这种方法是没用的。

      【讨论】:

        猜你喜欢
        • 2012-05-31
        • 2013-03-16
        • 2014-12-19
        • 2014-12-02
        • 1970-01-01
        • 2018-08-26
        • 2021-01-18
        • 1970-01-01
        相关资源
        最近更新 更多