Browse Source

add customizable server name

Gildas Chabot 6 years ago
parent
commit
a326e967ad
1 changed files with 6 additions and 2 deletions
  1. 6 2
      ms.go

+ 6 - 2
ms.go

@@ -17,6 +17,10 @@ func main() {
17 17
 	if os.Getenv("PORT") != "" {
18 18
 		port = os.Getenv("PORT")
19 19
 	}
20
+	serverName := "localhost"
21
+	if os.Getenv("SERVER_NAME") != "" {
22
+		serverName = os.Getenv("SERVER_NAME")
23
+	}
20 24
 
21 25
 	rand.Seed(time.Now().Unix())
22 26
 
@@ -26,8 +30,8 @@ func main() {
26 30
 
27 31
 	router.GET("/", func(c *gin.Context) {
28 32
 		c.HTML(http.StatusOK, "index.html", gin.H{
29
-			"websocket": "ws://localhost:" + port + "/ws",
30
-			"sse":       "http://localhost:" + port + "/sse",
33
+			"websocket": "ws://" + serverName + ":" + port + "/ws",
34
+			"sse":       "http://" + serverName + ":" + port + "/sse",
31 35
 		})
32 36
 	})
33 37
 	router.GET("/ws", websocketHandler(websocket.Upgrader{