We have an Azure Function App running on our development machine (http://locahost:7071/api) with negotiate
endpoint pointing to an Azure Serverless signalR instance. The function app has the following configuration:
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"
}
The typescript application's implementation to negotiate looks in a Promise<boolean>
function like the following code snippet:
const options: IHttpConnectionOptions = {
accessTokenFactory: () => '',
logger: this.logger,
logMessageContent: true,
headers: {
'x-ms-signalr-userid' : 'myuserid',
'x-functions-key' : 'myfunckey'
}
};
this.hubConnection = new signalR.HubConnectionBuilder()
.withUrl(`http://localhost:7071/api`, options)
.configureLogging(LogLevel.Information)
.withAutomaticReconnect()
.build();
this.hubConnection.start().then(() => {
this.logger?.log(LogLevel.Information, "Hub connection established.");
resolve(true);
})
.catch(error => {
this.logger?.log(LogLevel.Critical, `Unable to establish a connection to the hub. The start failed: ${error}`);
reject(false);
});
"dependencies": {
"@microsoft/signalr": "^7.0.5",
"rxjs": "^7.8.0",
"typescript": "~4.9.5"
}
Unfortunately this code running in Jest never "negotiates" successfully due to the following error message:
Failed to complete negotiation with the server: TypeError: fetch failed
Additional notes: The breakpoint never hits the Azure Function Function's negotiate
endpoint (in C#) when running the function app in debug mode.
As a side note, we also have a test .NET application that negotiates flawlessly whose negotiation routine is similar to the share code's implementation.
How to address this issue in this code snippet to make the negotiation work?