|
@@ -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 (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:') {
|
|
if (window.location.protocol === 'https:') {
|
|
- return `wss://${window.location.host}${suffix}`
|
|
|
|
|
|
+ return `wss://${window.location.host}${url}`
|
|
} else {
|
|
} 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开头的,就直接使用即可
|
|
// 如果配置的第三方服务直接是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 {
|
|
} 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
|
|
}
|
|
}
|