0

我正在用一个应用程序测试一些 SignalR,一切正常。现在要在服务器(azurewebsites)中对其进行测试,我需要将 baseUrl 设为动态并获取当前 url,以便可以建立 SignalR 集线器连接。

现在我有以下连接代码:

//server configuration
export let CONFIGURATION = {
    baseUrls: {
        server: 'http://localhost:51913'
    },
}

SomeMethod()
{
this.connection = $.hubConnection(CONFIGURATION.baseUrls.server);

//... the rest of the process to connect to the hub.
}

显然,这不适用于 localhost 作为 URL。如何获取主机 url 以开始我的连接?有什么方法可以获取它或从例如 WebConfig 中读取它?我只是不知道热它有效。

PS:也许有一些可能在没有特定网址的情况下连接到我的集线器?

4

2 回答 2

1

只是如果以后有人有同样的问题:

我会将静态地址放入环境中,它会相应地改变

于 2019-09-26T14:25:23.893 回答
1

您可以使用以下简单的代码行获取基本 url:

let baseUrl = this.document.location.origin;  
于 2019-09-26T14:15:52.860 回答