[ASP.net core + React.js] 解決 SignalR 卡在 start 不動的問題

[ASP.net core + React.js] 解決 SignalR 卡在 start 不動的問題

[ASP.net core + React.js] SignalR hangs on start


2023/01/19 14:54:01

問題簡介

「搭載 React.js 的 ASP.net Core」模板

加上 SignalR 服務後, connection.start() 會卡著、不接著執行 .then.catch

解決方法

ClientApp 的 setproxy.js 沒有讓 websocket 傳到後端去,同時 header 也不對,要改成

11
12
13
14
15
16
17
18
19
20
21
22
module.exports = function(app) {
const appProxy = createProxyMiddleware(context, {
target: target,
secure: false,
ws: true, // 允許 websocket
//headers: { // 額外的 header 需要刪掉
// Connection: 'Keep-Alive'
//}
});

app.use(appProxy);
};

以此紀錄