diff --git a/web/package.json b/web/package.json index e89a1be..c9382e4 100644 --- a/web/package.json +++ b/web/package.json @@ -1,6 +1,6 @@ { "name": "next-terminal", - "version": "0.0.5", + "version": "0.0.6", "private": true, "dependencies": { "@ant-design/icons": "^4.3.0", diff --git a/web/src/common/constants.js b/web/src/common/constants.js index 6b81e3c..5c3abe9 100644 --- a/web/src/common/constants.js +++ b/web/src/common/constants.js @@ -1,7 +1,14 @@ // prod +let wsPrefix; +if (window.location.protocol === 'https') { + wsPrefix = 'wss:' +} else { + wsPrefix = 'ws:' +} + export const server = ''; -export const wsServer = ''; -export const prefix = ''; +export const wsServer = wsPrefix + window.location.host; +export const prefix = window.location.protocol + ':' + window.location.host; // dev // export const server = '//127.0.0.1:8088'; diff --git a/web/src/common/request.js b/web/src/common/request.js index 2003103..4c914cc 100644 --- a/web/src/common/request.js +++ b/web/src/common/request.js @@ -1,12 +1,12 @@ import axios from 'axios' -import {prefix, server} from "./constants"; +import {server} from "./constants"; import {message} from 'antd'; import {getHeaders} from "../utils/utils"; // 测试地址 // axios.defaults.baseURL = server; // 线上地址 -axios.defaults.baseURL = server + prefix; +axios.defaults.baseURL = server; const handleError = (error) => { if ("Network Error" === error.toString()) { @@ -35,14 +35,14 @@ const request = { return new Promise((resolve, reject) => { axios.get(url, {headers: headers}) - .then((response) => { - handleResult(response.data); - resolve(response.data); - }) - .catch((error) => { - handleError(error); - reject(error); - }); + .then((response) => { + handleResult(response.data); + resolve(response.data); + }) + .catch((error) => { + handleError(error); + reject(error); + }); }) }, @@ -52,14 +52,14 @@ const request = { return new Promise((resolve, reject) => { axios.post(url, params, {headers: headers}) - .then((response) => { - handleResult(response.data); - resolve(response.data); - }) - .catch((error) => { - handleError(error); - reject(error); - }); + .then((response) => { + handleResult(response.data); + resolve(response.data); + }) + .catch((error) => { + handleError(error); + reject(error); + }); }) }, @@ -69,14 +69,14 @@ const request = { return new Promise((resolve, reject) => { axios.put(url, params, {headers: headers}) - .then((response) => { - handleResult(response.data); - resolve(response.data); - }) - .catch((error) => { - handleError(error); - reject(error); - }); + .then((response) => { + handleResult(response.data); + resolve(response.data); + }) + .catch((error) => { + handleError(error); + reject(error); + }); }) }, @@ -85,14 +85,14 @@ const request = { return new Promise((resolve, reject) => { axios.delete(url, {headers: headers}) - .then((response) => { - handleResult(response.data); - resolve(response.data); - }) - .catch((error) => { - handleError(error); - reject(error); - }); + .then((response) => { + handleResult(response.data); + resolve(response.data); + }) + .catch((error) => { + handleError(error); + reject(error); + }); }) }, @@ -101,14 +101,14 @@ const request = { return new Promise((resolve, reject) => { axios.patch(url, params, {headers: headers}) - .then((response) => { - handleResult(response.data); - resolve(response.data); - }) - .catch((error) => { - handleError(error); - reject(error); - }); + .then((response) => { + handleResult(response.data); + resolve(response.data); + }) + .catch((error) => { + handleError(error); + reject(error); + }); }) }, }; diff --git a/web/src/components/access/Access.js b/web/src/components/access/Access.js index f348092..d671569 100644 --- a/web/src/components/access/Access.js +++ b/web/src/components/access/Access.js @@ -19,7 +19,7 @@ import { } from 'antd' import qs from "qs"; import request from "../../common/request"; -import {prefix, server, wsServer} from "../../common/constants"; +import {server, wsServer} from "../../common/constants"; import { CloudDownloadOutlined, CloudUploadOutlined, @@ -406,7 +406,7 @@ class Access extends Component { async renderDisplay(sessionId, protocol) { - let tunnel = new Guacamole.WebSocketTunnel(wsServer + prefix + '/tunnel'); + let tunnel = new Guacamole.WebSocketTunnel(wsServer + '/tunnel'); tunnel.onstatechange = this.onTunnelStateChange; // Get new client instance @@ -658,7 +658,7 @@ class Access extends Component { message.warning('当前只支持下载文件'); return; } - download(`${server}${prefix}/sessions/${this.state.sessionId}/download?file=${this.state.selectNode.key}`); + download(`${server}/sessions/${this.state.sessionId}/download?file=${this.state.selectNode.key}`); } rmdir = async () => { @@ -711,7 +711,7 @@ class Access extends Component { } getTreeNodes = async (key) => { - const url = server + prefix + '/sessions/' + this.state.sessionId + '/ls?dir=' + key; + const url = server + '/sessions/' + this.state.sessionId + '/ls?dir=' + key; let result = await request.get(url); @@ -845,7 +845,7 @@ class Access extends Component { onCancel={this.handleUploadCancel} >