diff --git a/cmd/server/logger/sdkLogger.go b/cmd/server/logger/sdkLogger.go index 3709ce3da8355f9d6c54b5f9ae596ee769f284e1..800bab60ced234ab1fbab46425bf53bfb94071ca 100644 --- a/cmd/server/logger/sdkLogger.go +++ b/cmd/server/logger/sdkLogger.go @@ -1,13 +1,15 @@ /* * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. - * PilotGo-plugin-logs licensed under the Mulan Permissive Software License, Version 2. + * PilotGo-plugin-logs licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. - * Author: Wangjunqi123 + * Author: Wangjunqi123 * Date: Mon Dec 16 08:43:58 2024 +0800 */ package logger import ( + "os" + "gitee.com/openeuler/PilotGo-plugin-logs/cmd/server/conf" "gitee.com/openeuler/PilotGo/sdk/logger" ) @@ -16,5 +18,6 @@ func InitLogger() { err := logger.Init(conf.Global_Config.Logopts) if err != nil { logger.Fatal(err.Error()) + os.Exit(1) } } diff --git a/cmd/server/pluginclient/meta.go b/cmd/server/pluginclient/meta.go deleted file mode 100644 index 58dad3fb858f3b0be064fbef268cb007aa5fda88..0000000000000000000000000000000000000000 --- a/cmd/server/pluginclient/meta.go +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. - * PilotGo-plugin-logs licensed under the Mulan Permissive Software License, Version 2. - * See LICENSE file for more details. - * Author: Wangjunqi123 - * Date: Mon Dec 16 08:43:58 2024 +0800 - */ -package pluginclient - -import "gitee.com/openeuler/PilotGo/sdk/plugin/client" - -const Version = "1.0.1" - -var PluginInfo = &client.PluginInfo{ - Name: "logs", - Version: Version, - Description: "logs plugin for PilotGo", - Author: "wangjunqi", - Email: "wangjunqi@kylinos.cn", - Url: "", // 客户端建立连接的插件服务端地址,非插件配置文件中web服务器的监听地址 - Icon: "Reading", - MenuName: "主机日志", - PluginType: "micro-app", -} diff --git a/cmd/server/webserver/engine.go b/cmd/server/webserver/engine.go index baf961682d7e252c22a0b35f2fc59ad9d3df981e..254ff1c652bc420db294797e85b664b730cc2012 100644 --- a/cmd/server/webserver/engine.go +++ b/cmd/server/webserver/engine.go @@ -1,8 +1,8 @@ /* * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. - * PilotGo-plugin-logs licensed under the Mulan Permissive Software License, Version 2. + * PilotGo-plugin-logs licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. - * Author: Wangjunqi123 + * Author: Wangjunqi123 * Date: Mon Dec 16 08:43:58 2024 +0800 */ package webserver @@ -30,7 +30,6 @@ func InitWebServer() { engine := gin.New() engine.Use(gin.Recovery(), middleware.Logger([]string{ - "/plugin_manage/bind", "/", })) gin.SetMode(gin.ReleaseMode) @@ -87,7 +86,6 @@ func InitWebServer() { }() time.Sleep(100 * time.Millisecond) - pluginclient.Global_Client.Wait4Bind() } func pluginRouter(_engine *gin.Engine) { @@ -100,30 +98,5 @@ func pluginRouter(_engine *gin.Engine) { } func proxyRouter(_engine *gin.Engine) { - _engine.GET("/ws/proxy", WebsocketProxyHandle) + _engine.GET("/plugin/ws/logs", WebsocketProxyHandle) } - -// func testRouter(_engine *gin.Engine) { -// _engine.PUT("/files/:filename", func(_ctx *gin.Context) { -// filename, ok := _ctx.Params.Get("filename") -// if !ok { -// _ctx.JSON(http.StatusBadRequest, "path param error") -// return -// } - -// file, err := os.Create(fmt.Sprintf("/home/wjq/%s", filename)) -// if err != nil { -// _ctx.JSON(http.StatusBadRequest, fmt.Sprintf("fail to create file: %s, %s", filename, err.Error())) -// return -// } -// defer file.Close() - -// _, err = io.Copy(file, _ctx.Request.Body) -// if err != nil { -// _ctx.JSON(http.StatusBadRequest, fmt.Sprintf("io.copy error: %s", err.Error())) -// return -// } - -// _ctx.JSON(http.StatusCreated, "") -// }) -// } diff --git a/cmd/server/webserver/frontendResource/static.go b/cmd/server/webserver/frontendResource/static.go index 89fe006139c5b1129a2b8faccfcb79f969a1c141..2ccb9d9fe834834795312ed08935b7cf45a02ae4 100644 --- a/cmd/server/webserver/frontendResource/static.go +++ b/cmd/server/webserver/frontendResource/static.go @@ -1,12 +1,13 @@ +//go:build !production +// +build !production + /* * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. - * PilotGo-plugin-logs licensed under the Mulan Permissive Software License, Version 2. + * PilotGo-plugin-logs licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. - * Author: Wangjunqi123 + * Author: Wangjunqi123 * Date: Mon Dec 16 08:43:58 2024 +0800 */ -//go:build !production -// +build !production package frontendResource @@ -18,18 +19,16 @@ import ( ) func StaticRouter(router *gin.Engine) { - static := router.Group("/plugin/logs") - { - static.Static("/assets", "../web/dist/assets") - static.StaticFile("/", "../web/dist/index.html") + router.Static("/plugin/logs/assets", "../../web/dist/assets") + router.StaticFile("/plugin/logs", "../../web/dist/index.html") + + // 解决页面刷新404的问题 + router.NoRoute(func(c *gin.Context) { + if !strings.HasPrefix(c.Request.RequestURI, "/plugin/logs/api") { + c.File("../../web/dist/index.html") + return + } + c.AbortWithStatus(http.StatusNotFound) + }) - // 解决页面刷新404的问题 - router.NoRoute(func(c *gin.Context) { - if !strings.HasPrefix(c.Request.RequestURI, "/plugin/logs/api") { - c.File("../web/dist/index.html") - return - } - c.AbortWithStatus(http.StatusNotFound) - }) - } } diff --git a/web/src/view/socket.ts b/web/src/view/socket.ts index a92d99da08cfa7f7370339db6c381c10e2416d61..ff442ec6ef5d4ddbcae3036cc8096f784e48f26c 100644 --- a/web/src/view/socket.ts +++ b/web/src/view/socket.ts @@ -27,10 +27,10 @@ interface socket { reconnect: () => void } -let wsProtocol = window.location.protocol === 'http' ? 'ws://' : 'wss://'; +let wsProtocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; const socket: socket = { websocket: null, - connectURL: wsProtocol+"localhost:8888/plugin/ws/logs", + connectURL: wsProtocol + "localhost:9994/plugin/ws/logs", // 开启标识 socket_open: false, // 心跳timer @@ -60,7 +60,7 @@ const socket: socket = { return socket.websocket } */ - socket.websocket = new WebSocket(socket.connectURL+`?clientId=${useLogStore().clientId}`) + socket.websocket = new WebSocket(socket.connectURL + `?clientId=${useLogStore().clientId}`) socket.websocket.onmessage = (e: any) => { if (receiveMessage) { receiveMessage(e) @@ -68,7 +68,7 @@ const socket: socket = { } socket.websocket.onclose = (e: any) => { - console.log('检测到关闭',e) + console.log('检测到关闭', e) useLogStore().ws_isOpen = false; clearInterval(socket.hearbeat_interval) socket.socket_open = false @@ -102,8 +102,8 @@ const socket: socket = { } // 连接发生错误 - socket.websocket.onerror = function (e:any) { - console.log('连接发生错误',e) + socket.websocket.onerror = function (e: any) { + console.log('连接发生错误', e) useLogStore().ws_isOpen = false; } },