From ca3d0114d8a89be7bf8a42e3280eb383067712a2 Mon Sep 17 00:00:00 2001 From: wll8 Date: Wed, 21 Aug 2024 17:11:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=B7=B2=E8=B7=A8=E5=9F=9F=E7=9A=84=20BASE?= =?UTF-8?q?=5FAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 1 + .env.production | 1 + src/layout/index.vue | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.env.development b/.env.development index 52553ff..1be2541 100644 --- a/.env.development +++ b/.env.development @@ -6,6 +6,7 @@ VITE_APP_ENV = 'development' # 开发环境 VITE_APP_BASE_API = '/dev-api' +VITE_APP_WS_BASE_API = '/dev-api/resource/websocket' # 应用访问路径 例如使用前缀 /admin/ VITE_APP_CONTEXT_PATH = '/' diff --git a/.env.production b/.env.production index bf9e644..6add191 100644 --- a/.env.production +++ b/.env.production @@ -15,6 +15,7 @@ VITE_APP_SNAILJOB_ADMIN = '/snail-job' # 生产环境 VITE_APP_BASE_API = '/prod-api' +VITE_APP_WS_BASE_API = '/prod-api/resource/websocket' # 是否在打包时开启压缩,支持 gzip 和 brotli VITE_BUILD_COMPRESS = gzip diff --git a/src/layout/index.vue b/src/layout/index.vue index 29fb5ff..715334b 100644 --- a/src/layout/index.vue +++ b/src/layout/index.vue @@ -68,7 +68,9 @@ onMounted(() => { onMounted(() => { let protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://'; - initWebSocket(protocol + window.location.host + import.meta.env.VITE_APP_BASE_API + '/resource/websocket'); + const base = import.meta.env.VITE_APP_WS_BASE_API; + const wsUrl = base.includes(`://`) ? base : `${protocol}${window.location.host}${base}`; + initWebSocket(wsUrl); }); const handleClickOutside = () => {