瀏覽代碼

allow for secure protocols

Gildas Chabot 6 年之前
父節點
當前提交
b006f332b5
共有 1 個文件被更改,包括 6 次插入2 次删除
  1. 6 2
      ms.go

+ 6 - 2
ms.go

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