mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
优化 Websocket 连接
This commit is contained in:
parent
3c39e1537d
commit
7b5aae3e67
@ -35,6 +35,7 @@ func (cp *commonPage) home(c *gin.Context) {
|
|||||||
defer dao.ServerLock.RUnlock()
|
defer dao.ServerLock.RUnlock()
|
||||||
c.HTML(http.StatusOK, "page/home", mygin.CommonEnvironment(c, gin.H{
|
c.HTML(http.StatusOK, "page/home", mygin.CommonEnvironment(c, gin.H{
|
||||||
"Admin": admin,
|
"Admin": admin,
|
||||||
|
"Domain": dao.Conf.Site.Domain,
|
||||||
"Servers": dao.ServerList,
|
"Servers": dao.ServerList,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ServeWeb ..
|
// ServeWeb ..
|
||||||
func ServeWeb() {
|
func ServeWeb(port uint) {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
if dao.Conf.Debug {
|
if dao.Conf.Debug {
|
||||||
gin.SetMode(gin.DebugMode)
|
gin.SetMode(gin.DebugMode)
|
||||||
@ -43,7 +43,7 @@ func ServeWeb() {
|
|||||||
r.Static("/static", "resource/static")
|
r.Static("/static", "resource/static")
|
||||||
r.LoadHTMLGlob("resource/template/**/*")
|
r.LoadHTMLGlob("resource/template/**/*")
|
||||||
routers(r)
|
routers(r)
|
||||||
r.Run()
|
r.Run(fmt.Sprintf(":%d", port))
|
||||||
}
|
}
|
||||||
|
|
||||||
func routers(r *gin.Engine) {
|
func routers(r *gin.Engine) {
|
||||||
|
@ -47,7 +47,7 @@ func initDB() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
go controller.ServeWeb()
|
go controller.ServeWeb(80)
|
||||||
go rpc.ServeRPC()
|
go rpc.ServeRPC(5555)
|
||||||
select {}
|
select {}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@ -10,12 +11,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ServeRPC ...
|
// ServeRPC ...
|
||||||
func ServeRPC() {
|
func ServeRPC(port uint) {
|
||||||
server := grpc.NewServer()
|
server := grpc.NewServer()
|
||||||
pb.RegisterNezhaServiceServer(server, &rpcService.NezhaHandler{
|
pb.RegisterNezhaServiceServer(server, &rpcService.NezhaHandler{
|
||||||
Auth: &rpcService.AuthHandler{},
|
Auth: &rpcService.AuthHandler{},
|
||||||
})
|
})
|
||||||
listen, err := net.Listen("tcp", ":5555")
|
listen, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const ws = new WebSocket('ws://localhost:8080/ws');
|
const ws = new WebSocket('{{if eq .Domain "localhost"}}ws{{else}}wss{{end}}://{{.Domain}}/ws');
|
||||||
ws.onopen = function (evt) {
|
ws.onopen = function (evt) {
|
||||||
$.suiAlert({
|
$.suiAlert({
|
||||||
title: '实时通道建立',
|
title: '实时通道建立',
|
||||||
|
Loading…
Reference in New Issue
Block a user