소스 검색

优化环境变量配置

yanglzh 11 달 전
부모
커밋
3fc882309f

+ 13 - 16
.env

@@ -1,34 +1,31 @@
 # port 端口号
 VITE_PORT = 8888
 
-# open 运行 npm run dev 时自动打开浏览器
-VITE_OPEN = true
-
 # public path 配置线上环境路径(打包)、本地通过 http-server 访问时,请置空即可
 VITE_PUBLIC_PATH = /
 
-# 协议 例如 https:
-VITE_SERVER_PROTOCOL = ''
-# 网址或ip 如 baidu.com
-VITE_SERVER_HOSTNAME = ''
+# 服务端地址 空则使用打开页面的网址和端口作为服务地址,及前后端不分离  
+# 如果前端和服务端的地址不一样则必须配置服务端地址,必须是 http 或 https 开头 如 http://127.0.0.1:8200
+VITE_SERVER_ORIGIN = ''
+
+# api 地址前缀
+VITE_API_SUFFIX_URL = '/api/v1'
 
-# 前端路由模式 hash/history
+# 前端路由模式 hash/history, 默认使用 history。如果是在 go 中启动则需要配置成 hash 不然页面刷新会 404
 VITE_ROUTER_MODE = 'history'
 
-# 基础服务路径
-VITE_SERVER_URL = '/base-api'
-# 基础接口路径
-VITE_API_URL = '/base-api/api/v1'
-# 指数管理页面用到的
-VITE_ASSESS_URL = '/base-api/assess/v1'
+# NGINX 转发路径, 如果不使用nginx 则配置为空 ''
+VITE_NGINX_PROXY = '/base-api'
+# 指数管理服务
+VITE_ASSESS_URL = '/assess/v1'
 # 大屏前端
 VITE_SCREEN_URL = '/plugin/screen/index.html'
 # 组态图前端
 VITE_TOPO_URL = '/plugin/topo/index.html'
 # modbus服务
-VITE_MODBUS_API = '/base-api/modbus'
+VITE_MODBUS_API = '/modbus'
 # ice104协议网关服务
-VITE_ICE104_API = '/base-api/ice104'
+VITE_ICE104_API = '/ice104'
 
 # 规则引擎模式 sagoo-rule node-red
 VITE_RULE_MODEL = 'node-red'

+ 1 - 5
.env.development

@@ -1,5 +1 @@
-# VITE_SERVER_PROTOCOL = 'http:'
-# VITE_SERVER_HOSTNAME = '127.0.0.1:8200'
-
-VITE_SERVER_PROTOCOL = 'https:'
-VITE_SERVER_HOSTNAME = 'zhgy.sagoo.cn'
+VITE_SERVER_ORIGIN = 'https://zhgy.sagoo.cn'

+ 4 - 0
.env.go

@@ -0,0 +1,4 @@
+# NGINX 转发路径, 如果不使用nginx 则配置为空 '' 
+VITE_NGINX_PROXY = ''
+
+VITE_SERVER_ORIGIN = '127.0.0.1:8199'

+ 3 - 14
.env.golocal

@@ -1,16 +1,5 @@
-# 基础服务路径
-VITE_SERVER_URL = '/'
-# 基础接口路径
-VITE_API_URL = '/api/v1'
-# 指数管理页面用到的
-VITE_ASSESS_URL = '/assess/v1'
-# 大屏前端
-VITE_SCREEN_URL = '/plugin/screen/index.html'
-# 组态图前端
-VITE_TOPO_URL = '/plugin/topo/index.html'
-# modbus服务
-VITE_MODBUS_API = '/modbus'
-# ice104协议网关服务
-VITE_ICE104_API = '/ice104'
+# NGINX 转发路径, 如果不使用nginx 则配置为空 '' 
+VITE_NGINX_PROXY = ''
+
 # 前端路由模式
 VITE_ROUTER_MODE = 'hash'

+ 0 - 2
.env.open

@@ -1,4 +1,2 @@
-VITE_SERVER_PROTOCOL = ''
-VITE_SERVER_HOSTNAME = ''
 # 开源标识
 VITE_ISOPEN = true

+ 1 - 2
.env.production

@@ -1,2 +1 @@
-VITE_SERVER_PROTOCOL = ''
-VITE_SERVER_HOSTNAME = ''
+VITE_SERVER_ORIGIN = ''

+ 0 - 17
.env.test

@@ -1,17 +0,0 @@
-# VITE_SERVER_PROTOCOL = 'http:'
-# VITE_SERVER_HOSTNAME = '127.0.0.1:8200'
-
-# 基础服务路径
-VITE_SERVER_URL = ''
-# 基础接口路径
-VITE_API_URL = '/api/v1'
-# 指数管理页面用到的
-VITE_ASSESS_URL = '/assess/v1'
-# 大屏前端
-VITE_SCREEN_URL = '/plugin/screen/index.html'
-# 组态图前端
-VITE_TOPO_URL = '/plugin/topo/index.html'
-# modbus服务
-VITE_MODBUS_API = '/modbus'
-# ice104协议网关服务
-VITE_ICE104_API = '/ice104'

+ 0 - 5
README rule.md

@@ -1,5 +0,0 @@
-# 前端开发规范
-
-
-**请注意当前最新的分支为:professional2**
-

+ 2 - 13
README.md

@@ -29,16 +29,5 @@
 如本地开发设置`.env.development.local`如:
 
 ```shell
-VITE_SERVER_PROTOCOL = 'http:'
-VITE_SERVER_HOSTNAME = '127.0.0.1:8199'
-
-# 基础服务路径 - GO 本地
-VITE_SERVER_URL = ''
-VITE_API_URL = '/api/v1'
-
-# 规则引擎模式 sagoo-rule node-red
-VITE_RULE_MODEL = 'sagoo-rule'
-
-```
-
-<el-form :model="params" inline ref="queryRef" @submit.prevent @keyup.enter="queryList">
+VITE_SERVER_ORIGIN = 'http://127.0.0.1:8199'
+```

+ 1 - 10
package.json

@@ -6,20 +6,11 @@
   "license": "MIT",
   "scripts": {
     "dev": "vite --force",
+    "dev:go": "vite --force --mode go",
     "build": "vite build && npm run getVersion",
     "build:dev": "vite build --mode development && npm run getVersion",
     "build:golocal": "vite build --mode golocal && npm run getVersion",
     "build:open": "vite build --mode open && npm run getVersion",
-    "build:test": "vite build --mode test && npm run getVersion",
-    "deploy:zip": "npm run build && npm run zipAndUpload && npm run unzip && npm run success",
-    "zipAndUpload": "cd dist && rm -rf zhgy.sagoo.cn.zip && zip -r -q zhgy.sagoo.cn.zip ./ && ssh iot 'sudo rm /www/wwwroot/zhgy.sagoo.cn-old.zip' | ssh iot 'sudo mv /www/wwwroot/zhgy.sagoo.cn.zip /www/wwwroot/zhgy.sagoo.cn-old.zip' | scp -r -O zhgy.sagoo.cn.zip iot:/www/wwwroot",
-    "unzip": "ssh iot 'cd /www/wwwroot/ && sudo unzip -q -o -d ./zhgy.sagoo.cn zhgy.sagoo.cn.zip'",
-    "success": "echo '\\033[31m 部署完成 \\033[0m'",
-    "deploy": "npm run build && npm run deploy:rm && npm run deploy:scp && npm run deploy:auth | npm run success",
-    "deploy:rm": "ssh iot 'rm -rf /www/wwwroot/zhgy.sagoo.cn-copy/* && rm -rf /www/wwwroot/zhgy.sagoo.cn-pre/*'",
-    "deploy:scp": "scp -r -O ./dist/* iot:/www/wwwroot/zhgy.sagoo.cn-pre/ && ssh iot 'cd /www/wwwroot/zhgy.sagoo.cn/ && mv `ls | grep -v plugin` ../zhgy.sagoo.cn-copy && mv ../zhgy.sagoo.cn-pre/* ./'",
-    "deploy:auth": "ssh iot 'chown -R www /www/wwwroot/zhgy.sagoo.cn/'",
-    "lint-fix": "eslint --fix --ext .js --ext .jsx --ext .vue src/",
     "getVersion": "node ./getVersion.mjs",
     "updateVersion:small": "node ./updateVersion.mjs --patch",
     "updateVersion:mid": "node ./updateVersion.mjs --minor",

+ 2 - 2
src/api/assess/index.ts

@@ -1,7 +1,7 @@
 import { get, post, del, put } from '/@/utils/request';
-import getOrigin from '/@/utils/origin';
+import { getOtherServersOrigin } from '/@/utils/origin';
 
-const baseUrl = getOrigin(import.meta.env.VITE_ASSESS_URL);
+const baseUrl = getOtherServersOrigin(import.meta.env.VITE_ASSESS_URL);
 
 export default {
   getList: (params?: object) => get(baseUrl + '/setup', params),

+ 0 - 2
src/api/certificateManagement/index.ts

@@ -1,6 +1,4 @@
 import { get, post, del, put, file } from '/@/utils/request';
-import getOrigin from '/@/utils/origin';
-const baseUrl = getOrigin(import.meta.env.VITE_SERVER_URL);
 
 export default {
   certificateManagement: {

+ 0 - 2
src/api/scene/index.ts

@@ -1,6 +1,4 @@
 import { get, post, del, put, file } from '/@/utils/request';
-import getOrigin from '/@/utils/origin';
-const baseUrl = getOrigin(import.meta.env.VITE_SERVER_URL);
 
 export default {
   manage: {

+ 1 - 1
src/components/upload-wrapper/index.vue

@@ -12,7 +12,7 @@ import type { UploadProps } from 'element-plus';
 import getOrigin from '/@/utils/origin'
 import { getToken } from "/@/utils/auth";
 
-const uploadUrl: string = getOrigin(import.meta.env.VITE_API_URL + '/common/singleImg');
+const uploadUrl: string = getOrigin('/common/singleImg');
 
 const source = localStorage.uploadFileWay
 

+ 2 - 11
src/components/upload/button.vue

@@ -1,14 +1,5 @@
 <template>
-	<el-upload
-		:accept="accept"
-		:show-file-list="false"
-		v-model:file-list="fileList"
-		:limit="1"
-		:headers="headers"
-		:before-upload="beforeAvatarUpload"
-		:action="uploadUrl"
-		:on-success="updateImg"
-	>
+	<el-upload :accept="accept" :show-file-list="false" v-model:file-list="fileList" :limit="1" :headers="headers" :before-upload="beforeAvatarUpload" :action="uploadUrl" :on-success="updateImg">
 		<el-button style="margin-left: 12px;">
 			<el-icon> <ele-Upload /> </el-icon>
 			数据导入
@@ -47,7 +38,7 @@ const fileList = ref<any[]>([
 	// },
 ]);
 
-const uploadUrl: string = getOrigin(import.meta.env.VITE_API_URL + props.url);
+const uploadUrl: string = getOrigin(props.url);
 
 const updateImg = (res: any) => {
 	if (res.code === 0) {

+ 1 - 1
src/components/upload/index.vue

@@ -31,7 +31,7 @@ import type { UploadProps } from 'element-plus'
 import getOrigin from '/@/utils/origin'
 import { getToken } from "/@/utils/auth";
 
-const uploadUrl: string = getOrigin(import.meta.env.VITE_API_URL + '/common/singleImg')
+const uploadUrl: string = getOrigin('/common/singleImg')
 
 const headers = {
 	Authorization: 'Bearer ' + getToken(),

+ 1 - 1
src/components/upload/uploadFile.vue

@@ -40,7 +40,7 @@ const fileList = ref<any[]>([
 	// },
 ]);
 
-const uploadUrl: string = getOrigin(import.meta.env.VITE_API_URL + props.url);
+const uploadUrl: string = getOrigin(props.url);
 
 const updateImg = (res: any) => {
 

+ 2 - 2
src/layout/navBars/breadcrumb/userNews.vue

@@ -23,7 +23,7 @@
 <script lang="ts" setup>
 import { ref } from 'vue';
 import { useRouter } from 'vue-router';
-import getOrigin from '/@/utils/origin';
+import { getSSEOrigin } from '/@/utils/origin';
 import { ElNotification } from 'element-plus';
 
 const router = useRouter();
@@ -43,7 +43,7 @@ const newsList = ref<any[]>([
 // });
 
 // 监听系统消息的SSE
-const es = new EventSource(getOrigin(import.meta.env.VITE_SERVER_URL + '/subscribe/sysMessage?userId=' + localStorage.userId));
+const es = new EventSource(getSSEOrigin('/subscribe/sysMessage?userId=' + localStorage.userId));
 es.addEventListener('lastUnRead', ({ data }) => {
 	if (!data || data === 'null') return;
 	const list = JSON.parse(data);

+ 1 - 1
src/utils/common.ts

@@ -3,7 +3,7 @@ import getOrigin from '/@/utils/origin'
  * 通用js方法封装处理
  */
 
-const baseURL: string | undefined | boolean = getOrigin(import.meta.env.VITE_API_URL)
+const baseURL: string | undefined | boolean = getOrigin()
 
 
 export function getUpFileUrl(url: string) {

+ 29 - 12
src/utils/origin.ts

@@ -1,23 +1,40 @@
-export default function getOrigin(suffix: string = '', type: string = 'http') {
+export default function getOrigin(urlStr: string = '', type: string = 'http') {
+  const origin = import.meta.env.VITE_SERVER_ORIGIN
+  const nginxProxy = import.meta.env.VITE_NGINX_PROXY
+  const suffixUrl = import.meta.env.VITE_API_SUFFIX_URL
+  const url = nginxProxy + suffixUrl + urlStr
   if (type === 'ws') {
-    if (import.meta.env.VITE_SERVER_PROTOCOL === 'https:') {
-      return `wss://${import.meta.env.VITE_SERVER_HOSTNAME}${suffix}`
-    } else if (!import.meta.env.VITE_SERVER_PROTOCOL) {
+    if (origin.includes('https://')) {
+      return origin.repalce('https://', 'wss://') + url
+    } else if (!origin) {
       if (window.location.protocol === 'https:') {
-        return `wss://${window.location.host}${suffix}`
+        return `wss://${window.location.host}${url}`
       } else {
-        return `ws://${window.location.host}${suffix}`
+        return `ws://${window.location.host}${url}`
       }
     }
-    return `ws://${import.meta.env.VITE_SERVER_HOSTNAME}${suffix}`
+    return origin.repalce('http://', 'ws://') + url
   }
 
   // 如果配置的第三方服务直接是http开头的,就直接使用即可
-  if (suffix.includes('http')) {
-    return suffix
-  } else if (import.meta.env.VITE_SERVER_HOSTNAME) {
-    return `${import.meta.env.VITE_SERVER_PROTOCOL}//${import.meta.env.VITE_SERVER_HOSTNAME}${suffix}`
+  if (urlStr.includes('http')) {
+    return urlStr
+  } else if (origin) {
+    return `${origin}${url}`
   } else {
-    return `${window.location.protocol}//${window.location.host}${suffix}`
+    return `${window.location.origin}${url}`
   }
+}
+
+// 如果 modbus服务  ice104协议网关服务 指数管理服务
+export function getOtherServersOrigin(urlStr: string = '') {
+  const origin = import.meta.env.VITE_SERVER_ORIGIN
+  const nginxProxy = import.meta.env.VITE_NGINX_PROXY
+  return origin + nginxProxy + urlStr
+}
+
+export function getSSEOrigin(urlStr: string = '') {
+  const origin = import.meta.env.VITE_SERVER_ORIGIN
+  const nginxProxy = import.meta.env.VITE_NGINX_PROXY
+  return origin + nginxProxy + urlStr
 }

+ 1 - 1
src/utils/request.ts

@@ -5,7 +5,7 @@ import { getToken, removeToken } from "/@/utils/auth";
 
 // 配置新建一个 axios 实例
 const service = axios.create({
-	baseURL: getOrigin(import.meta.env.VITE_API_URL),
+	baseURL: getOrigin(),
 	timeout: 120000,
 	headers: { 'Content-Type': 'application/json' },
 });

+ 2 - 2
src/utils/request_ice104.ts

@@ -1,11 +1,11 @@
 import axios from 'axios';
 import { ElMessage, ElMessageBox } from 'element-plus';
-import getOrigin from '/@/utils/origin'
+import { getOtherServersOrigin } from '/@/utils/origin'
 import { getToken, removeToken } from "/@/utils/auth";
 
 // 配置新建一个 axios 实例
 const service = axios.create({
-	baseURL: getOrigin(import.meta.env.VITE_ICE104_API),
+	baseURL: getOtherServersOrigin(import.meta.env.VITE_ICE104_API),
 	// baseURL: 'http://jfg4xi.natappfree.cc',
 	timeout: 120000,
 	headers: { 'Content-Type': 'application/json' },

+ 2 - 2
src/utils/request_modbus.ts

@@ -1,11 +1,11 @@
 import axios from 'axios';
 import { ElMessage, ElMessageBox } from 'element-plus';
-import getOrigin from '/@/utils/origin'
+import { getOtherServersOrigin } from '/@/utils/origin'
 import { getToken, removeToken } from "/@/utils/auth";
 
 // 配置新建一个 axios 实例
 const service = axios.create({
-	baseURL: getOrigin(import.meta.env.VITE_MODBUS_API),
+	baseURL: getOtherServersOrigin(import.meta.env.VITE_MODBUS_API),
 	timeout: 120000,
 	headers: { 'Content-Type': 'application/json' },
 });

+ 3 - 4
src/views/iot/device/channel/component/detail.vue

@@ -67,7 +67,7 @@
 <script lang="ts">
 import { ElMessage, ElMessageBox } from 'element-plus';
 import api from '/@/api/device/modbus';
-import getOrigin from '/@/utils/origin';
+import { getOtherServersOrigin } from '/@/utils/origin';
 import TaskDialog from './taskDialog.vue';
 
 export default {
@@ -114,7 +114,7 @@ export default {
 			this.dialogVisible = true;
 		},
 		downloadLog() {
-			window.open(getOrigin(import.meta.env.VITE_MODBUS_API) + '/debug/export_message?number=' + this.temp.number);
+			window.open(getOtherServersOrigin(import.meta.env.VITE_MODBUS_API) + '/debug/export_message?number=' + this.temp.number);
 		},
 		closeDialog() {
 			this.dialogVisible = false;
@@ -198,8 +198,7 @@ export default {
 		// 码流
 		initEv() {
 			if (this.evsrc) return;
-			// this.evsrc = new EventSource(`http://one.server.mydig.net/debug?number=${this.temp.number}`);
-			this.evsrc = new EventSource(`${getOrigin(import.meta.env.VITE_MODBUS_API)}/debug?number=${this.temp.number}`);
+			this.evsrc = new EventSource(`${getOtherServersOrigin(import.meta.env.VITE_MODBUS_API)}/debug?number=${this.temp.number}`);
 			let that = this;
 			this.evsrc.onmessage = function (ev: any) {
 				try {

+ 1 - 1
src/views/iot/device/instance/component/excel.vue

@@ -65,7 +65,7 @@ interface DicState {
 export default defineComponent({
   setup(prop, { emit }) {
 
-    const uploadUrl: string = getOrigin(import.meta.env.VITE_API_URL + "/product/device/import");
+    const uploadUrl: string = getOrigin("/product/device/import");
     const headers = {
       Authorization: 'Bearer ' + getToken(),
     };

+ 1 - 1
src/views/iot/device/product/component/editPro.vue

@@ -165,7 +165,7 @@ export default defineComponent({
 	components: { EditCategory, uploadVue },
 	setup(prop, { emit }) {
 		const formRef = ref<HTMLElement | null>(null)
-		const baseURL: string | undefined | boolean = getOrigin(import.meta.env.VITE_API_URL)
+		const baseURL: string | undefined | boolean = getOrigin()
 
 		const { proxy } = getCurrentInstance() as any
 		const { network_server_type } = proxy.useDict('network_server_type')

+ 1 - 1
src/views/iot/device/product/detail.vue

@@ -235,7 +235,7 @@ export default defineComponent({
 
 	setup(prop, context) {
 
-		const uploadUrl: string = getOrigin(import.meta.env.VITE_API_URL + "/product/tsl/import");
+		const uploadUrl: string = getOrigin("/product/tsl/import");
 		const headers = {
 			Authorization: 'Bearer ' + getToken(),
 		};

+ 2 - 2
src/views/iot/device/template/index.vue

@@ -61,7 +61,7 @@ import ImportFile from './component/importFile.vue';
 import api from '/@/api/device/modbus';
 import { ElMessageBox, ElMessage } from 'element-plus';
 import { useSearch } from '/@/hooks/useCommonModbus';
-import getOrigin from '/@/utils/origin'
+import { getOtherServersOrigin } from '/@/utils/origin'
 
 const importFile = ref();
 const editFormRef = ref();
@@ -81,7 +81,7 @@ const handleImport = async (row: any) => {
 };
 
 const handleExport = async (row: any) => {
-	window.open(getOrigin(import.meta.env.VITE_MODBUS_API + '/data_area/export?number=' + row.number))
+	window.open(getOtherServersOrigin(import.meta.env.VITE_MODBUS_API + '/data_area/export?number=' + row.number))
 };
 
 // 重置表单

+ 1 - 1
src/views/iot/ota-update/update/component/edit.vue

@@ -153,7 +153,7 @@ export default defineComponent({
       },
     ]);
     const state = reactive<UpdateState>({
-      uploadUrl: getOrigin(import.meta.env.VITE_API_URL + '/common/singleFile'), // 上传地址
+      uploadUrl: getOrigin('/common/singleFile'), // 上传地址
       isShowDialog: false,
       ruleForm: {
         id: 0,

+ 1 - 1
src/views/iot/property/dossier/component/from.vue

@@ -53,7 +53,7 @@ export default defineComponent({
     }
   },
   setup(prop, { emit }) {
-    const uploadUrl = getOrigin(import.meta.env.VITE_API_URL + '/common/singleFile')
+    const uploadUrl = getOrigin('/common/singleFile')
     const headers = {
       Authorization: 'Bearer ' + getToken(),
     }

+ 1 - 1
src/views/login/component/account.vue

@@ -136,7 +136,7 @@ export default defineComponent({
 		};
 
 		function authLogin(type: string) {
-			window.open(getOrigin(import.meta.env.VITE_API_URL + '/oauth/login?provider=' + type))
+			window.open(getOrigin('/oauth/login?provider=' + type))
 			// if (type === 'gitee') {
 			// 	const client_id = 'a0585ded445f240f2adc7957989bdd644fa2cdf0db7d98b0a940ec92df6a0934'
 			// 	const redirect_uri = 'http://localhost:8888/#/sso/gitee'

+ 1 - 1
src/views/system/assess/component/editPro.vue

@@ -100,7 +100,7 @@ export default defineComponent({
   components: { uploadVue },
   setup(prop, { emit }) {
     const formRef = ref<HTMLElement | null>(null);
-    const baseURL: string | undefined | boolean = getOrigin(import.meta.env.VITE_API_URL)
+    const baseURL: string | undefined | boolean = getOrigin()
 
     const state = reactive<DicState>({
       isShowDialog: false,

+ 2 - 2
src/views/system/monitor/cache/index.vue

@@ -325,7 +325,7 @@
 <script lang="ts">
 import { toRefs, reactive, defineComponent } from 'vue';
 import 'echarts-wordcloud';
-import getOrigin from '/@/utils/origin'
+import { getSSEOrigin } from '/@/utils/origin'
 let interval: any = null;
 let es: any = null;
 export default defineComponent({
@@ -338,7 +338,7 @@ export default defineComponent({
     });
 
     function startWs() {
-      es = new EventSource(getOrigin(import.meta.env.VITE_SERVER_URL + "/subscribe/redisinfo"));
+      es = new EventSource(getSSEOrigin("/subscribe/redisinfo"));
 
       es.addEventListener("stats", statsInfoMsg);
       es.addEventListener("clients", clientsInfoMsg);

+ 2 - 2
src/views/system/monitor/lastLinesLog/index.vue

@@ -55,7 +55,7 @@
 <script lang="ts" setup>
 import api from '/@/api/system';
 import { useSearch } from '/@/hooks/useCommon';
-import getOrigin from '/@/utils/origin'
+import { getSSEOrigin } from '/@/utils/origin'
 import downloadFile from '/@/utils/download';
 import { ref, nextTick, onMounted, onUnmounted } from 'vue';
 import { ElMessage, ElMessageBox } from "element-plus";
@@ -104,7 +104,7 @@ const view = (row: any) => {
   if (types.value == 'run') {
     row.name = row.value;
   }
-  es = new EventSource(getOrigin(import.meta.env.VITE_SERVER_URL + "/subscribe/logInfo?name=" + row.name + '&types=' + types.value));
+  es = new EventSource(getSSEOrigin("/subscribe/logInfo?name=" + row.name + '&types=' + types.value));
   es.addEventListener('log', ({ data }) => {
     topMsg.value.unshift(data);
   });

+ 2 - 2
src/views/system/monitor/server/index.vue

@@ -223,7 +223,7 @@ import { ref, toRefs, reactive, onMounted, getCurrentInstance, defineComponent }
 import * as echarts from 'echarts';
 import 'echarts-wordcloud';
 import dayjs from 'dayjs';
-import getOrigin from '/@/utils/origin'
+import { getSSEOrigin } from '/@/utils/origin'
 let interval: any = null;
 let es: any = null;
 export default defineComponent({
@@ -685,7 +685,7 @@ export default defineComponent({
     });
 
     function startWs() {
-      es = new EventSource(getOrigin(import.meta.env.VITE_SERVER_URL + "/subscribe/sysenv"));
+      es = new EventSource(getSSEOrigin("/subscribe/sysenv"));
 
       es.addEventListener("host", displayHost);
       es.addEventListener("mem", displayMem);

+ 5 - 5
vite.config.ts

@@ -37,17 +37,17 @@ const viteConfig = defineConfig((mode: ConfigEnv) => {
 			open: true,
 			hmr: true,
 			proxy: {
-				[env.VITE_API_URL]: {
-					target: `${env.VITE_SERVER_PROTOCOL}//${env.VITE_SERVER_HOSTNAME}`,
+				[env.VITE_API_SUFFIX_URL]: {
+					target: env.VITE_SERVER_ORIGIN,
 					ws: true,
 					changeOrigin: true,
 					// rewrite: (path) => path.replace(/^\/api/, ''),
 				},
-				['/base-api' + env.VITE_API_URL]: {
-					target: `${env.VITE_SERVER_PROTOCOL}//${env.VITE_SERVER_HOSTNAME}`,
+				[env.VITE_SERVER_ORIGIN + env.VITE_API_SUFFIX_URL]: {
+					target: env.VITE_SERVER_ORIGIN,
 					ws: true,
 					changeOrigin: true,
-					rewrite: (path) => path.replace(/^\/base-api/, ''),
+					rewrite: (path) => path.replace(env.VITE_SERVER_ORIGIN, ''),
 				},
 			},
 		},