From 8179a5c6a336beacf5103f8152db6111c0ece170 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 18 Sep 2024 09:43:47 +0200 Subject: [PATCH] feat: custom terminal host --- docker-compose.prod.yml | 3 ++ .../project/shared/terminal.blade.php | 38 +++++++++++++------ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 3eb270a2a..9777c52df 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -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 diff --git a/resources/views/livewire/project/shared/terminal.blade.php b/resources/views/livewire/project/shared/terminal.blade.php index 8aca10a0f..d54bb7c63 100644 --- a/resources/views/livewire/project/shared/terminal.blade.php +++ b/resources/views/livewire/project/shared/terminal.blade.php @@ -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) => {