From d280b4ddea76b0f1824f1fe1dcdacca70354adbf Mon Sep 17 00:00:00 2001 From: powerfool Date: Tue, 12 Nov 2024 11:32:20 +0800 Subject: [PATCH] fix(terminal): use wss protocol to connect terminal when https is available (#625) --- ui/src/components/Terminal/terminal.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ui/src/components/Terminal/terminal.tsx b/ui/src/components/Terminal/terminal.tsx index c2ab5e3f3..4f0806690 100644 --- a/ui/src/components/Terminal/terminal.tsx +++ b/ui/src/components/Terminal/terminal.tsx @@ -1,7 +1,8 @@ -import { intl } from '@/utils/intl'; -import { Terminal } from '@xterm/xterm'; import { Button, Modal } from 'antd'; + import React from 'react'; +import { Terminal } from '@xterm/xterm'; +import { intl } from '@/utils/intl'; export interface ITerminal { terminalId: string; @@ -34,8 +35,11 @@ export const OBTerminal: React.FC = (props) => { const cols = Math.floor(containerWidth / 9.2); const rows = Math.floor(cols / 4); term.resize(cols, rows); + + const protocol = location.protocol === 'https:' ? 'wss' : 'ws'; + const ws = new WebSocket( - `ws://${location.host}/api/v1/terminal/${terminalId}?cols=${cols}&rows=${rows}`, + `${protocol}://${location.host}/api/v1/terminal/${terminalId}?cols=${cols}&rows=${rows}`, ); term.write('Hello from \x1B[1;3;31mOceanBase\x1B[0m\r\n');