File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -80,10 +80,7 @@ func handleMessages() {
8080
8181func Start () {
8282 r := mux .NewRouter ()
83- port := os .Getenv ("PORT" )
84- if port == "" {
85- log .Fatal ("$PORT must be set" )
86- }
83+
8784 r .HandleFunc ("/ws" , handleConnections )
8885 go handleMessages ()
8986
@@ -92,10 +89,19 @@ func Start() {
9289 r .HandleFunc ("/interfaces" , InterfaceMethod )
9390 r .HandleFunc ("/startmining" , StartMining )
9491 fmt .Printf ("Server started on port :%v \n " , port )
95- portString := fmt .Sprintf (":%v" , port )
96- err := http .ListenAndServe (portString , r )
92+ err := http .ListenAndServe (GetPort (), r )
9793 if err != nil {
9894 fmt .Printf ("Could not start the server: %v" , err )
9995 }
10096
10197}
98+
99+ func GetPort () string {
100+ var port = os .Getenv ("PORT" )
101+ // Set a default port if there is nothing in the environment
102+ if port == "" {
103+ port = "4747"
104+ fmt .Println ("INFO: No PORT environment variable detected, defaulting to " + port )
105+ }
106+ return ":" + port
107+ }
You can’t perform that action at this time.
0 commit comments