feat: 支持直接定义已跨域的 BASE_API

This commit is contained in:
wll8 2024-08-21 17:11:23 +08:00
parent ee99ed8e76
commit ca3d0114d8
3 changed files with 5 additions and 1 deletions

View File

@ -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 = '/'

View File

@ -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

View File

@ -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 = () => {