diff --git a/cmd/dashboard/controller/common_page.go b/cmd/dashboard/controller/common_page.go index b041b3a..031c923 100644 --- a/cmd/dashboard/controller/common_page.go +++ b/cmd/dashboard/controller/common_page.go @@ -35,6 +35,7 @@ func (cp *commonPage) home(c *gin.Context) { defer dao.ServerLock.RUnlock() c.HTML(http.StatusOK, "page/home", mygin.CommonEnvironment(c, gin.H{ "Admin": admin, + "Domain": dao.Conf.Site.Domain, "Servers": dao.ServerList, })) } diff --git a/cmd/dashboard/controller/controller.go b/cmd/dashboard/controller/controller.go index 03bb713..a8416f9 100644 --- a/cmd/dashboard/controller/controller.go +++ b/cmd/dashboard/controller/controller.go @@ -13,7 +13,7 @@ import ( ) // ServeWeb .. -func ServeWeb() { +func ServeWeb(port uint) { gin.SetMode(gin.ReleaseMode) if dao.Conf.Debug { gin.SetMode(gin.DebugMode) @@ -43,7 +43,7 @@ func ServeWeb() { r.Static("/static", "resource/static") r.LoadHTMLGlob("resource/template/**/*") routers(r) - r.Run() + r.Run(fmt.Sprintf(":%d", port)) } func routers(r *gin.Engine) { diff --git a/cmd/dashboard/main.go b/cmd/dashboard/main.go index 976507a..daf2ccd 100644 --- a/cmd/dashboard/main.go +++ b/cmd/dashboard/main.go @@ -47,7 +47,7 @@ func initDB() { } func main() { - go controller.ServeWeb() - go rpc.ServeRPC() + go controller.ServeWeb(80) + go rpc.ServeRPC(5555) select {} } diff --git a/cmd/dashboard/rpc/rpc.go b/cmd/dashboard/rpc/rpc.go index 33fdd88..0adac6b 100644 --- a/cmd/dashboard/rpc/rpc.go +++ b/cmd/dashboard/rpc/rpc.go @@ -1,6 +1,7 @@ package rpc import ( + "fmt" "net" "google.golang.org/grpc" @@ -10,12 +11,12 @@ import ( ) // ServeRPC ... -func ServeRPC() { +func ServeRPC(port uint) { server := grpc.NewServer() pb.RegisterNezhaServiceServer(server, &rpcService.NezhaHandler{ Auth: &rpcService.AuthHandler{}, }) - listen, err := net.Listen("tcp", ":5555") + listen, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) if err != nil { panic(err) } diff --git a/resource/template/page/home.html b/resource/template/page/home.html index 45c9740..772186f 100644 --- a/resource/template/page/home.html +++ b/resource/template/page/home.html @@ -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) { $.suiAlert({ title: '实时通道建立',