Skip to content

Commit 8179a5c

Browse files
committed
feat: custom terminal host
1 parent d051815 commit 8179a5c

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

docker-compose.prod.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ services:
4646
- PUSHER_APP_ID
4747
- PUSHER_APP_KEY
4848
- PUSHER_APP_SECRET
49+
- TERMINAL_PROTOCOL
50+
- TERMINAL_HOST
51+
- TERMINAL_PORT
4952
- AUTOUPDATE
5053
- SELF_HOSTED
5154
- SSH_MUX_ENABLED

resources/views/livewire/project/shared/terminal.blade.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,34 @@ function keepAlive() {
5050
5151
function initializeWebSocket() {
5252
if (!socket || socket.readyState === WebSocket.CLOSED) {
53-
// Only use port if Coolify is used with ip (so it has a port in the url)
54-
let postPath = ':6002/terminal/ws';
55-
const port = window.location.port;
56-
if (!port) {
57-
postPath = '/terminal/ws';
53+
const predefined = {
54+
protocol: "{{ env('TERMINAL_PROTOCOL') }}",
55+
host: "{{ env('TERMINAL_HOST') }}",
56+
port: "{{ env('TERMINAL_PORT') }}"
5857
}
59-
let url = window.location.hostname;
60-
// make sure the port is not included
61-
url = url.split(':')[0];
62-
socket = new WebSocket((window.location.protocol === 'https:' ? 'wss://' : 'ws://') +
63-
url +
64-
postPath);
58+
const connectionString = {
59+
protocol: window.location.protocol === 'https:' ? 'wss' : 'ws',
60+
host: window.location.hostname,
61+
port: ":6002",
62+
path: '/terminal/ws'
63+
}
64+
if (predefined.host) {
65+
connectionString.host = predefined.host
66+
}
67+
if (predefined.port) {
68+
connectionString.port = `:${predefined.port}`
69+
}
70+
if (predefined.protocol) {
71+
connectionString.protocol = predefined.protocol
72+
}
73+
if (!window.location.port) {
74+
connectionString.port = ''
75+
}
76+
console.log(connectionString)
77+
const url =
78+
`${connectionString.protocol}://${connectionString.host}${connectionString.port}${connectionString.path}`
79+
console.log(url)
80+
socket = new WebSocket(url);
6581
6682
socket.onmessage = handleSocketMessage;
6783
socket.onerror = (e) => {

0 commit comments

Comments
 (0)