diff --git a/api/notification/live.go b/api/notification/live.go index 25e8c6cf..83e62977 100644 --- a/api/notification/live.go +++ b/api/notification/live.go @@ -5,6 +5,7 @@ import ( "github.com/0xJacky/Nginx-UI/model" "github.com/gin-gonic/gin" "io" + "time" ) func Live(c *gin.Context) { @@ -19,15 +20,27 @@ func Live(c *gin.Context) { notification.SetClient(c, evtChan) notify := c.Writer.CloseNotify() - go func() { - <-notify - notification.RemoveClient(c) - }() - for n := range evtChan { - c.Stream(func(w io.Writer) bool { - c.SSEvent("message", n) - return false - }) + c.Stream(func(w io.Writer) bool { + c.SSEvent("heartbeat", "") + return false + }) + + for { + select { + case n := <-evtChan: + c.Stream(func(w io.Writer) bool { + c.SSEvent("message", n) + return false + }) + case <-time.After(30 * time.Second): + c.Stream(func(w io.Writer) bool { + c.SSEvent("heartbeat", "") + return false + }) + case <-notify: + notification.RemoveClient(c) + return + } } } diff --git a/app/src/components/Notification/Notification.vue b/app/src/components/Notification/Notification.vue index c88f1045..3d2c8997 100644 --- a/app/src/components/Notification/Notification.vue +++ b/app/src/components/Notification/Notification.vue @@ -58,7 +58,6 @@ function newSSE() { // reconnect s.onerror = reconnect - s.onabort = reconnect return s } diff --git a/app/src/version.json b/app/src/version.json index fa3bffac..6824179f 100644 --- a/app/src/version.json +++ b/app/src/version.json @@ -1 +1 @@ -{"version":"2.0.0-beta.39","build_id":1,"total_build":368} \ No newline at end of file +{"version":"2.0.0-beta.39","build_id":3,"total_build":370} \ No newline at end of file diff --git a/internal/nginx/ngx_conf_parse_test.go b/internal/nginx/ngx_conf_parse_test.go index 964bc10e..51100652 100644 --- a/internal/nginx/ngx_conf_parse_test.go +++ b/internal/nginx/ngx_conf_parse_test.go @@ -14,7 +14,8 @@ func TestNgxConfParse(t *testing.T) { fmt.Println(err) return } - n := p.Parse() + + n, _ := p.Parse() fn(n.Block, 0)