🚀 修改生产环境 api 路径.

This commit is contained in:
lijiahangmax
2024-02-25 00:17:33 +08:00
parent 3ee0037bc7
commit a4e884658b
10 changed files with 42 additions and 17 deletions

View File

@@ -1,3 +1,31 @@
const debug = import.meta.env.MODE !== 'production';
// http base url
export const httpBaseUrl = (() => {
const configBase = import.meta.env.VITE_API_BASE_URL;
if (configBase.startsWith('http')) {
// 固定
return configBase;
} else {
// 动态
const protocol = window.location.protocol;
const host = window.location.host;
return `${protocol}//${host}${configBase}`;
}
})();
// websocket base url
export const webSocketBaseUrl = (() => {
const configBase = import.meta.env.VITE_WS_BASE_URL;
if (configBase.startsWith('ws')) {
// 固定
return configBase;
} else {
// 动态
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const host = window.location.host;
return `${protocol}//${host}${configBase}`;
}
})();
export default debug;