Parcourir la source

/sys/log 页面根据 HTTP 协议来决定使用 wss 还是 ws 前缀

reghao il y a 2 ans
Parent
commit
d5803bc0af

+ 1 - 4
manager/src/main/resources/static/js/websocket.js

@@ -5,7 +5,6 @@ WebSocketClient.prototype._generateEndpoint = function () {
     let protocol = location.protocol
     let hostname = location.hostname
     let port = location.port
-
     let prefix;
     if (protocol === 'https') {
         if (port === 443) {
@@ -21,9 +20,7 @@ WebSocketClient.prototype._generateEndpoint = function () {
         }
     }
 
-    var host1 = window.location.host
-    var url = 'wss://' + host1 + '/ws/ssh?token=12345678'
-    return  url;
+    return  prefix + '/ws/ssh?token=12345678'
 };
 
 WebSocketClient.prototype.connect = function (options) {

+ 19 - 2
manager/src/main/resources/templates/sys/syslog.html

@@ -64,8 +64,25 @@
             var host = 'localhost'
             var params = 'token=' + token + '&app=' + app + '&host=' + host;
 
-            var host1 = window.location.host
-            var url = 'wss://' + host1 + '/ws/log/pull?' + params
+            let protocol = location.protocol
+            let hostname = location.hostname
+            let port = location.port
+            let prefix;
+            if (protocol === 'https') {
+                if (port === 443) {
+                    prefix = 'wss://' + hostname;
+                } else {
+                    prefix = 'wss://' + hostname + ':' + port;
+                }
+            } else {
+                if (port === 80) {
+                    prefix = 'ws://' + hostname;
+                } else {
+                    prefix = 'ws://' + hostname + ':' + port;
+                }
+            }
+
+            var url = prefix + '/ws/log/pull?' + params
             ws = new WebSocket(url);
             ws.onopen = function() {
                 connected = true