I have a simple NodeJS app like the below
index.js
const signalR = require("@microsoft/signalr");
//Works if I disable TLS validation
//process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
let connection = new signalR.HubConnectionBuilder()
.withUrl("https://myapp.mydomain.com:5000/messageHub",
//.withUrl("http://myapp.mydomain.com:5002/messageHub", //works if I use http
{
withCredentials: false
})
.withAutomaticReconnect()
.configureLogging(signalR.LogLevel.Information)
.build();
connection.logging = true;
async function start() {
try {
await connection.start({ withCredentials: false });
console.log("SignalR Connected.");
} catch (err) {
console.log(err);
setTimeout(start, 5000);
}
};
connection.onclose(async () => {
await start();
});
start();
package.json个
{
"name": "Client",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@microsoft/signalr": "8.0.0"
}
}
- 它在 node 17.9.1(或更早版本)上工作正常,在 node 18.0.0(或更高版本)上失败
- 如果我使用http而不是HTTPS,它会起作用
- 如果我禁用TLS验证,它会起作用,但我当然不想这样做
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
个
我的服务器在.NET 8上使用SignalR 8.
当我运行应用程序node index.js
时,我收到
[2024-02-08T11:06:44.246Z] Error: Failed to complete negotiation with the server: TypeError: fetch failed
[2024-02-08T11:06:44.246Z] Error: Failed to start the connection: Error: Failed to complete negotiation with the server: TypeError: fetch failed
FailedToNegotiateWithServerError: Failed to complete negotiation with the server: TypeError: fetch failed
at HttpConnection._getNegotiationResponse (C:\dev\20240227electron\node_modules\@microsoft\signalr\dist\cjs\HttpConnection.js:257:35)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async HttpConnection._startInternal (C:\dev\20240227electron\node_modules\@microsoft\signalr\dist\cjs\HttpConnection.js:170:41)
at async HttpConnection.start (C:\dev\20240227electron\node_modules\@microsoft\signalr\dist\cjs\HttpConnection.js:73:9)
at async HubConnection._startInternal (C:\dev\20240227electron\node_modules\@microsoft\signalr\dist\cjs\HubConnection.js:135:9)
at async HubConnection._startWithStateTransitions (C:\dev\20240227electron\node_modules\@microsoft\signalr\dist\cjs\HubConnection.js:112:13)
at async Timeout.start [as _onTimeout] (C:\dev\20240227electron\index.js:18:9) {
有什么主意吗?