fix: 通知 SSE 长连接被 Nginx 60s 超时掐断
This commit is contained in:
@@ -58,6 +58,7 @@ const NotificationBell: React.FC = () => {
|
||||
const token = useUserStore.getState().token;
|
||||
if (!token) return;
|
||||
const es = new EventSource(`/api/notifications/stream?token=${encodeURIComponent(token)}`);
|
||||
es.onopen = () => setSseDown(false);
|
||||
es.onmessage = (event) => {
|
||||
try {
|
||||
JSON.parse(event.data);
|
||||
@@ -68,7 +69,7 @@ const NotificationBell: React.FC = () => {
|
||||
}
|
||||
};
|
||||
es.onerror = () => {
|
||||
es.close();
|
||||
// 不主动关闭:EventSource 会自动重连,主动关闭会导致一次超时后实时通知永久断流
|
||||
setSseDown(true);
|
||||
};
|
||||
return () => {
|
||||
|
||||
Reference in New Issue
Block a user