()
| 6 | |
| 7 | class ProxyServer { |
| 8 | constructor() { |
| 9 | this.called = false; |
| 10 | this.lastReq = null; |
| 11 | this.httpServer = http.createServer((req, res) => { |
| 12 | this.called = true; |
| 13 | this.lastReq = req; |
| 14 | res.writeHead(200, { 'Content-Type': 'text/plain' }); |
| 15 | res.end('okay'); |
| 16 | }); |
| 17 | this.httpServer.listen(3001); |
| 18 | |
| 19 | let wsServer = new WebSocketServer({ |
| 20 | httpServer: this.httpServer, |
| 21 | autoAcceptConnections: true, |
| 22 | }); |
| 23 | |
| 24 | let websocketEvents = (this.websocketEvents = []); |
| 25 | wsServer.on('connect', (connection) => { |
| 26 | websocketEvents.push('connect'); |
| 27 | |
| 28 | connection.on('message', (message) => { |
| 29 | websocketEvents.push(`message: ${message.utf8Data}`); |
| 30 | connection.sendUTF(message.utf8Data); |
| 31 | }); |
| 32 | |
| 33 | connection.on('error', (error) => { |
| 34 | websocketEvents.push(`error: ${error}`); |
| 35 | }); |
| 36 | |
| 37 | connection.on('close', () => { |
| 38 | websocketEvents.push(`close`); |
| 39 | }); |
| 40 | }); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | module.exports = ProxyServer; |
nothing calls this directly
no test coverage detected