Skip to content

Commit d9d8bee

Browse files
committed
feat: upstream health check #166
1 parent b2854d4 commit d9d8bee

File tree

14 files changed

+275
-292
lines changed

14 files changed

+275
-292
lines changed

api/upstream/router.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package upstream
2+
3+
import "github.com/gin-gonic/gin"
4+
5+
func InitRouter(r *gin.RouterGroup) {
6+
r.GET("/availability_test", AvailabilityTest)
7+
}

api/upstream/upstream.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package upstream
2+
3+
import (
4+
"github.com/0xJacky/Nginx-UI/internal/logger"
5+
"github.com/0xJacky/Nginx-UI/internal/upstream"
6+
"github.com/gin-gonic/gin"
7+
"github.com/gorilla/websocket"
8+
"net/http"
9+
"time"
10+
)
11+
12+
func AvailabilityTest(c *gin.Context) {
13+
var upGrader = websocket.Upgrader{
14+
CheckOrigin: func(r *http.Request) bool {
15+
return true
16+
},
17+
}
18+
// upgrade http to websocket
19+
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
20+
if err != nil {
21+
logger.Error(err)
22+
return
23+
}
24+
25+
defer ws.Close()
26+
27+
var body []string
28+
29+
err = ws.ReadJSON(&body)
30+
31+
if err != nil {
32+
logger.Error(err)
33+
return
34+
}
35+
36+
for {
37+
err = ws.WriteJSON(upstream.AvailabilityTest(body))
38+
39+
if err != nil {
40+
logger.Error(err)
41+
}
42+
43+
time.Sleep(10 * time.Second)
44+
}
45+
}

app/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"vue-router": "^4.2.5",
3535
"vue3-ace-editor": "2.2.4",
3636
"vue3-apexcharts": "^1.4.4",
37-
"vue3-gettext": "3.0.0-beta.2",
37+
"vue3-gettext": "^3.0.0-beta.3",
3838
"vuedraggable": "^4.1.0",
3939
"xterm": "^5.3.0",
4040
"xterm-addon-attach": "^0.9.0",
@@ -67,8 +67,7 @@
6767
"unplugin-auto-import": "^0.17.1",
6868
"unplugin-vue-components": "^0.25.2",
6969
"unplugin-vue-define-options": "^1.4.0",
70-
"vite": "^5.0.8",
71-
"vite-plugin-html": "^3.2.0",
70+
"vite": "^5.0.9",
7271
"vite-svg-loader": "^5.1.0",
7372
"vue-tsc": "^1.8.22"
7473
}

0 commit comments

Comments
 (0)