feat: custom terminal host

This commit is contained in:
Andras Bacsai
2024-09-18 09:43:47 +02:00
parent d0518153fb
commit 8179a5c6a3
2 changed files with 30 additions and 11 deletions

View File

@@ -46,6 +46,9 @@ services:
- PUSHER_APP_ID
- PUSHER_APP_KEY
- PUSHER_APP_SECRET
- TERMINAL_PROTOCOL
- TERMINAL_HOST
- TERMINAL_PORT
- AUTOUPDATE
- SELF_HOSTED
- SSH_MUX_ENABLED

View File

@@ -50,18 +50,34 @@
function initializeWebSocket() {
if (!socket || socket.readyState === WebSocket.CLOSED) {
// Only use port if Coolify is used with ip (so it has a port in the url)
let postPath = ':6002/terminal/ws';
const port = window.location.port;
if (!port) {
postPath = '/terminal/ws';
const predefined = {
protocol: "{{ env('TERMINAL_PROTOCOL') }}",
host: "{{ env('TERMINAL_HOST') }}",
port: "{{ env('TERMINAL_PORT') }}"
}
let url = window.location.hostname;
// make sure the port is not included
url = url.split(':')[0];
socket = new WebSocket((window.location.protocol === 'https:' ? 'wss://' : 'ws://') +
url +
postPath);
const connectionString = {
protocol: window.location.protocol === 'https:' ? 'wss' : 'ws',
host: window.location.hostname,
port: ":6002",
path: '/terminal/ws'
}
if (predefined.host) {
connectionString.host = predefined.host
}
if (predefined.port) {
connectionString.port = `:${predefined.port}`
}
if (predefined.protocol) {
connectionString.protocol = predefined.protocol
}
if (!window.location.port) {
connectionString.port = ''
}
console.log(connectionString)
const url =
`${connectionString.protocol}://${connectionString.host}${connectionString.port}${connectionString.path}`
console.log(url)
socket = new WebSocket(url);
socket.onmessage = handleSocketMessage;
socket.onerror = (e) => {