diff --git a/core/init/router/proxy.go b/core/init/router/proxy.go index b51d8d991..60dda8d0e 100644 --- a/core/init/router/proxy.go +++ b/core/init/router/proxy.go @@ -13,18 +13,31 @@ import ( "github.com/gin-gonic/gin" ) +var wsUrl = map[string]struct{}{ + "/api/v2/process/ws": {}, + "/api/v2/files/wget/process": {}, + + "/api/v2/containers/search/log": {}, +} + func Proxy() gin.HandlerFunc { return func(c *gin.Context) { - if strings.HasPrefix(c.Request.URL.Path, "/1panel/swagger") || !strings.HasPrefix(c.Request.URL.Path, "/api/v2") { + reqPath := c.Request.URL.Path + if strings.HasPrefix(reqPath, "/1panel/swagger") || !strings.HasPrefix(c.Request.URL.Path, "/api/v2") { c.Next() return } - if strings.HasPrefix(c.Request.URL.Path, "/api/v2/core") && !strings.HasPrefix(c.Request.URL.Path, "/api/v2/core/xpack") { + if strings.HasPrefix(reqPath, "/api/v2/core") && !strings.HasPrefix(c.Request.URL.Path, "/api/v2/core/xpack") { c.Next() return } + var currentNode string + if _, ok := wsUrl[reqPath]; ok { + currentNode = c.Query("currentNode") + } else { + currentNode = c.Request.Header.Get("CurrentNode") + } - currentNode := c.Request.Header.Get("CurrentNode") if !strings.HasPrefix(c.Request.URL.Path, "/api/v2/core") && (currentNode == "local" || len(currentNode) == 0 || currentNode == "127.0.0.1") { sockPath := "/etc/1panel/agent.sock" if _, err := os.Stat(sockPath); err != nil { diff --git a/frontend/src/components/log/container/index.vue b/frontend/src/components/log/container/index.vue index c901f3821..94df87125 100644 --- a/frontend/src/components/log/container/index.vue +++ b/frontend/src/components/log/container/index.vue @@ -45,6 +45,8 @@ import { onUnmounted, reactive, ref } from 'vue'; import { ElMessageBox } from 'element-plus'; import { MsgError, MsgSuccess } from '@/utils/message'; import hightlight from '@/components/log/custom-hightlight/index.vue'; +import { GlobalStore } from '@/store'; +const globalStore = GlobalStore(); const props = defineProps({ container: { @@ -125,9 +127,10 @@ const searchLogs = async () => { return; } logs.value = []; - let url = `/api/v2/containers/search/log?container=${logSearch.container}&since=${logSearch.mode}&tail=${logSearch.tail}&follow=${logSearch.isWatch}`; + let currentNode = globalStore.currentNode; + let url = `/api/v2/containers/search/log?container=${logSearch.container}&since=${logSearch.mode}&tail=${logSearch.tail}&follow=${logSearch.isWatch}¤tNode=${currentNode}`; if (logSearch.compose !== '') { - url = `/api/v2/containers/search/log?compose=${logSearch.compose}&since=${logSearch.mode}&tail=${logSearch.tail}&follow=${logSearch.isWatch}`; + url = `/api/v2/containers/search/log?compose=${logSearch.compose}&since=${logSearch.mode}&tail=${logSearch.tail}&follow=${logSearch.isWatch}¤tNode=${currentNode}`; } eventSource = new EventSource(url); eventSource.onmessage = (event: MessageEvent) => { diff --git a/frontend/src/views/host/file-management/process/index.vue b/frontend/src/views/host/file-management/process/index.vue index 1e19dcc82..c3b3c468f 100644 --- a/frontend/src/views/host/file-management/process/index.vue +++ b/frontend/src/views/host/file-management/process/index.vue @@ -52,6 +52,8 @@ import { fileWgetKeys } from '@/api/modules/files'; import { computeSize } from '@/utils/util'; import { onBeforeUnmount, ref } from 'vue'; import MsgInfo from '@/components/msg-info/index.vue'; +import { GlobalStore } from '@/store'; +const globalStore = GlobalStore(); let processSocket = ref(null) as unknown as WebSocket; const res = ref([]); @@ -87,7 +89,8 @@ const initProcess = () => { let href = window.location.href; let protocol = href.split('//')[0] === 'http:' ? 'ws' : 'wss'; let ipLocal = href.split('//')[1].split('/')[0]; - processSocket = new WebSocket(`${protocol}://${ipLocal}/api/v2/files/wget/process`); + let currentNode = globalStore.currentNode; + processSocket = new WebSocket(`${protocol}://${ipLocal}/api/v2/files/wget/process?currentNode=${currentNode}`); processSocket.onopen = onOpenProcess; processSocket.onmessage = onMessage; processSocket.onerror = onerror; diff --git a/frontend/src/views/host/process/network/index.vue b/frontend/src/views/host/process/network/index.vue index 6f79cdff5..f14385d2f 100644 --- a/frontend/src/views/host/process/network/index.vue +++ b/frontend/src/views/host/process/network/index.vue @@ -82,6 +82,8 @@