Skip to content
Prev Previous commit
Next Next commit
Adding comments
  • Loading branch information
Ian Walter committed Mar 20, 2021
commit c8ec891be4b91e36d0ca4ca68201b8e209be278c
11 changes: 9 additions & 2 deletions apps/kdot-port-reverse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ ws.on('data', message => {
socket.write(message.data)
}
} else {
logger.error()
logger.warn()
}
})

server.on('connection', socket => {
// Create a unique ID for the connection.
const id = nanoid()
logger.debug(`Connection ${id}`)

// Store the socket so it can be retrieved when theres a response through the
// websocket.
connections[id] = socket

// const data = []
Expand Down Expand Up @@ -65,7 +69,10 @@ server.on('connection', socket => {
}
})

socket.on('end', () => ws.send({ id, end: true }))
socket.on('end', () => {
//
delete connections[id]
})
})

server.listen(3000)