@@ -50,18 +50,34 @@ function keepAlive() {
50
50
51
51
function initializeWebSocket () {
52
52
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' ) } }"
58
57
}
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);
65
81
66
82
socket .onmessage = handleSocketMessage;
67
83
socket .onerror = (e ) => {
0 commit comments