Просмотр исходного кода

fix: 兼容带端口号情况下的网址访问后端

yanglzh 2 лет назад
Родитель
Сommit
61a5d22eec
1 измененных файлов с 3 добавлено и 3 удалено
  1. 3 3
      src/utils/origin.ts

+ 3 - 3
src/utils/origin.ts

@@ -4,9 +4,9 @@ export default function getOrigin(suffix: string = '', type: string = 'http') {
       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.host}${suffix}`
       } else {
-        return `ws://${window.location.hostname}${suffix}`
+        return `ws://${window.location.host}${suffix}`
       }
     }
     return `ws://${import.meta.env.VITE_SERVER_HOSTNAME}${suffix}`
@@ -15,6 +15,6 @@ export default function getOrigin(suffix: string = '', type: string = 'http') {
   if (import.meta.env.VITE_SERVER_HOSTNAME) {
     return `${import.meta.env.VITE_SERVER_PROTOCOL}//${import.meta.env.VITE_SERVER_HOSTNAME}${suffix}`
   } else {
-    return `${window.location.protocol}//${window.location.hostname}${suffix}`
+    return `${window.location.protocol}//${window.location.host}${suffix}`
   }
 }