🚀 修改生产环境 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,10 +1,10 @@
{
"local": {
"baseUrl": "http://127.0.0.1:9200/orion-api",
"baseUrl": "http://127.0.0.1:9200/orion/api",
"token": "Bearer YQJ3IpwJJv5HujIWY6ZTNDgUxXRY6aDt"
},
"gateway": {
"baseUrl": "http://127.0.0.1:9200/orion-api",
"baseUrl": "http://127.0.0.1:9200/orion/api",
"token": "Bearer YQJ3IpwJJv5HujIWY6ZTNDgUxXRY6aDt"
}
}

View File

@@ -123,7 +123,7 @@ orion:
version: @revision@
api:
# 公共 api 前缀
prefix: /orion-api
prefix: /orion/api
# 是否开启跨域
cors: true
websocket:

View File

@@ -1,4 +1,4 @@
VITE_API_BASE_URL= 'http://127.0.0.1:9200/orion-api'
VITE_API_BASE_URL= 'http://127.0.0.1:9200/orion/api'
VITE_WS_BASE_URL= 'ws://127.0.0.1:9200/orion/keep-alive'
VITE_APP_VERSION= '1.0.0'
VITE_SFTP_PREVIEW_MB= 2

View File

@@ -1,4 +1,4 @@
VITE_API_BASE_URL= 'http://127.0.0.1:9200/orion-api'
VITE_WS_BASE_URL= 'ws://127.0.0.1:9200/orion/keep-alive'
VITE_API_BASE_URL= '/orion/api'
VITE_WS_BASE_URL= '/orion/keep-alive'
VITE_APP_VERSION= '1.0.0'
VITE_SFTP_PREVIEW_MB= 2

View File

@@ -3,6 +3,7 @@ import axios from 'axios';
import { Message } from '@arco-design/web-vue';
import { useUserStore } from '@/store';
import { getToken } from '@/utils/auth';
import { httpBaseUrl } from '@/utils/env';
import { reLoginTipsKey } from '@/types/symbol';
export interface HttpResponse<T = unknown> {
@@ -13,9 +14,7 @@ export interface HttpResponse<T = unknown> {
axios.defaults.timeout = 10000;
axios.defaults.promptBizErrorMessage = true;
if (import.meta.env.VITE_API_BASE_URL) {
axios.defaults.baseURL = import.meta.env.VITE_API_BASE_URL;
}
axios.defaults.baseURL = httpBaseUrl;
axios.interceptors.request.use(
(config: AxiosRequestConfig) => {

View File

@@ -10,7 +10,7 @@
<span title="当前版本">v{{ version }}</span>
</a-space>
<span class="copyright">
Copyright<icon-copyright /> 2023 By lijiahang
Copyright<icon-copyright /> 2024 By lijiahang
</span>
</a-space>
</a-layout-footer>

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;

View File

@@ -4,11 +4,10 @@ import { TransferReceiverType, TransferStatus, TransferType } from '../types/ter
import { Message } from '@arco-design/web-vue';
import { getTerminalAccessToken } from '@/api/asset/host-terminal';
import { nextId } from '@/utils';
import { webSocketBaseUrl } from '@/utils/env';
import SftpTransferUploader from './sftp-transfer-uploader';
import SftpTransferDownloader from './sftp-transfer-downloader';
export const wsBase = import.meta.env.VITE_WS_BASE_URL;
// sftp 传输管理器实现
export default class SftpTransferManager implements ISftpTransferManager {
@@ -99,7 +98,7 @@ export default class SftpTransferManager implements ISftpTransferManager {
// 获取 access
const { data: accessToken } = await getTerminalAccessToken();
// 打开会话
this.client = new WebSocket(`${wsBase}/host/transfer/${accessToken}`);
this.client = new WebSocket(`${webSocketBaseUrl}/host/transfer/${accessToken}`);
this.client.onerror = event => {
// 打开失败将传输列表置为失效
Message.error('会话打开失败');

View File

@@ -3,10 +3,9 @@ import { OutputProtocol } from '../types/terminal.protocol';
import { getTerminalAccessToken } from '@/api/asset/host-terminal';
import { Message } from '@arco-design/web-vue';
import { sleep } from '@/utils';
import { webSocketBaseUrl } from '@/utils/env';
import TerminalOutputProcessor from './terminal-output-processor';
export const wsBase = import.meta.env.VITE_WS_BASE_URL;
// 终端通信处理器 实现
export default class TerminalChannel implements ITerminalChannel {
@@ -23,7 +22,7 @@ export default class TerminalChannel implements ITerminalChannel {
// 获取 access
const { data: accessToken } = await getTerminalAccessToken();
// 打开会话
this.client = new WebSocket(`${wsBase}/host/terminal/${accessToken}`);
this.client = new WebSocket(`${webSocketBaseUrl}/host/terminal/${accessToken}`);
this.client.onerror = event => {
Message.error('无法连接至服务器');
console.error('error', event);

View File

@@ -88,7 +88,7 @@
// 默认标题
document.title = TerminalTabs.NEW_CONNECTION.title;
// 注册关闭视口事件
if (debug) {
if (!debug) {
window.addEventListener('beforeunload', handleBeforeUnload);
}
});