修复了https下ws连接出错的问题

This commit is contained in:
梦凌汐 2025-05-06 19:39:14 +08:00
parent b33a3eb201
commit 974f20e035
2 changed files with 5 additions and 3 deletions

2
.env
View File

@ -1,6 +1,6 @@
S3_ENDPOINT=http://hk.meowdream.cn:5246
S3_ACCESS_KEY=s7R9zBdnQcw6FtR8Wr0J
S3_SECRET_KEY=FoobOUNWN7fDL7Zh0fkXP3d0plP
S3_SECRET_KEY=FoobOUNWN7fDL7Zh0fkXP3d0plP/GOvzdv84baw3
S3_BUCKET=image
MONGO_URI=mongodb://hk.meowdream.cn:27017
MONGO_DB=catism_image

View File

@ -164,7 +164,8 @@ function fetchUserTheme() {
function initWebSocket() {
const userKey = localStorage.getItem('userKey');
socket = new WebSocket(`ws://${window.location.host}/ws/user-info?key=${userKey}`);
const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
socket = new WebSocket(`${protocol}://${window.location.host}/ws/user-info?key=${userKey}`);
// 初始化时获取并应用主题
fetchUserTheme().then(theme => {
@ -208,7 +209,8 @@ function reconnectWebSocket() {
setTimeout(() => {
const userKey = localStorage.getItem('userKey');
socket = new WebSocket(`ws://${window.location.host}/ws/user-info?key=${userKey}`);
const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
socket = new WebSocket(`${protocol}://${window.location.host}/ws/user-info?key=${userKey}`);
socket.onopen = function() {
reconnectAttempts = 0;
console.log('WebSocket重新连接成功');