Selaa lähdekoodia

allow for secure protocols

Gildas Chabot 6 vuotta sitten
vanhempi
commit
b006f332b5
1 muutettua tiedostoa jossa 6 lisäystä ja 2 poistoa
  1. 6 2
      ms.go

+ 6 - 2
ms.go

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