浏览代码

修复ws地址获取错误

yanglzh 2 年之前
父节点
当前提交
4ec3b6e670
共有 1 个文件被更改,包括 5 次插入4 次删除
  1. 5 4
      src/utils/origin.ts

+ 5 - 4
src/utils/origin.ts

@@ -1,16 +1,17 @@
 export default function getOrigin(suffix: string = '', type: string = 'http') {
   if (type === 'ws') {
     if (import.meta.env.VITE_SERVER_PROTOCOL === 'https:') {
-      return `wss//${import.meta.env.VITE_SERVER_HOSTNAME}${suffix}`
+      return `wss://${import.meta.env.VITE_SERVER_HOSTNAME}${suffix}`
     } else if (!import.meta.env.VITE_SERVER_PROTOCOL) {
       if (window.location.protocol === 'https:') {
-        return `wss//${window.location.hostname}${suffix}`
+        return `wss://${window.location.hostname}${suffix}`
+      } else {
+        return `ws://${window.location.hostname}${suffix}`
       }
     }
-    return `ws//${import.meta.env.VITE_SERVER_HOSTNAME}${suffix}`
+    return `ws://${import.meta.env.VITE_SERVER_HOSTNAME}${suffix}`
   }
 
-
   if (import.meta.env.VITE_SERVER_HOSTNAME) {
     return `${import.meta.env.VITE_SERVER_PROTOCOL}//${import.meta.env.VITE_SERVER_HOSTNAME}${suffix}`
   } else {