4
4
"encoding/json"
5
5
"log"
6
6
"net/http"
7
+ "os"
7
8
"sync"
8
9
9
10
"github.com/gin-gonic/gin"
@@ -38,7 +39,11 @@ type Message struct {
38
39
39
40
func verifyToken (token string ) bool {
40
41
client := & http.Client {}
41
- req , err := http .NewRequest ("GET" , "http://localhost:3001/auth/verify-token" , nil )
42
+ USER_SERVICE_URI := os .Getenv ("USER_SERVICE_URI" )
43
+ if USER_SERVICE_URI == "" {
44
+ USER_SERVICE_URI = "http://localhost:3001"
45
+ }
46
+ req , err := http .NewRequest ("GET" , USER_SERVICE_URI + "/auth/verify-token" , nil )
42
47
if err != nil {
43
48
log .Println ("Error creating request:" , err )
44
49
return false
@@ -140,8 +145,6 @@ func handleMessages(client *Client, hub *Hub) {
140
145
break
141
146
}
142
147
143
- log .Printf ("Received" )
144
-
145
148
var msgData map [string ]interface {}
146
149
if err := json .Unmarshal (message , & msgData ); err != nil {
147
150
log .Printf ("Failed to parse message: %v" , err )
@@ -168,7 +171,6 @@ func handleMessages(client *Client, hub *Hub) {
168
171
}
169
172
170
173
if msgData ["type" ] == "close_session" {
171
- log .Println ("It's time" )
172
174
closeMessage := Message {
173
175
roomID : client .roomID ,
174
176
content : []byte ("The session has been closed by a user." ),
@@ -224,5 +226,9 @@ func main() {
224
226
// Status endpoint
225
227
r .GET ("/status" , statusHandler (hub ))
226
228
227
- r .Run (":4000" )
229
+ PORT := os .Getenv ("PORT" )
230
+ if PORT == "" {
231
+ PORT = ":4000"
232
+ }
233
+ r .Run (PORT )
228
234
}
0 commit comments