From b59f4069ca8638e98b1cd6f7efbeb472671fd510 Mon Sep 17 00:00:00 2001 From: jingrow Date: Sun, 28 Dec 2025 22:38:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=9F=E4=BA=A7=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=B8=8Bsocket.js=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/src2/socket.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/dashboard/src2/socket.js b/dashboard/src2/socket.js index 27fb4f7..022b23b 100644 --- a/dashboard/src2/socket.js +++ b/dashboard/src2/socket.js @@ -5,13 +5,23 @@ import { getCachedResource, getCachedListResource } from 'jingrow-ui'; export function initSocket() { let host = window.location.hostname; let siteName = window.site_name; - let port = window.location.port ? `:${socketio_port}` : ''; - let protocol = port ? 'http' : 'https'; + let protocol = window.location.protocol.slice(0, -1); // 移除末尾的 ':' + + // 开发模式:使用 socketio_port(有端口或明确是开发环境) + // 生产模式:使用当前页面的协议和域名,不指定端口(通过 nginx 反向代理) + let port = ''; + if (window.location.port) { + // 开发模式或有明确端口,使用 socketio_port + port = `:${socketio_port}`; + } + // 生产模式(HTTPS 443 或 HTTP 80):不指定端口,使用当前页面的协议和域名 + let url = `${protocol}://${host}${port}/${siteName}`; let socket = io(url, { withCredentials: true, - reconnectionAttempts: 5 + reconnectionAttempts: 5, + secure: protocol === 'https' }); socket.on('refetch_resource', data => {