Skip to content

Commit 40ef593

Browse files
Copilotdgreif
andcommitted
Move WebSocket server code to separate file test/websocket-server.js
Co-authored-by: dgreif <[email protected]>
1 parent 4758c3b commit 40ef593

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

scripts/test-with-server.sh

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
#!/bin/bash
22

33
# Start the WebSocket server in the background
4-
node -e "
5-
const ws = require('nodejs-websocket');
6-
ws.createServer(function (conn) {
7-
conn.on('text', function (msg) {
8-
if (msg.startsWith('echo:')) {
9-
conn.sendText(msg.replace('echo:', ''));
10-
} else if (msg.startsWith('close:')) {
11-
const code = msg.replace('close:', '');
12-
conn.close(parseInt(code), 'reason');
13-
}
14-
});
15-
conn.on('error', function (error) {
16-
if (error.code !== 'ECONNRESET') throw error;
17-
});
18-
}).listen(7999, () => console.log('WebSocket server ready'));
19-
" &
4+
node test/websocket-server.js &
205

216
SERVER_PID=$!
227

test/websocket-server.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import ws from 'nodejs-websocket'
2+
3+
ws.createServer(function (conn) {
4+
conn.on('text', function (msg) {
5+
if (msg.startsWith('echo:')) {
6+
conn.sendText(msg.replace('echo:', ''))
7+
} else if (msg.startsWith('close:')) {
8+
const code = msg.replace('close:', '')
9+
conn.close(parseInt(code), 'reason')
10+
}
11+
})
12+
conn.on('error', function (error) {
13+
if (error.code !== 'ECONNRESET') throw error
14+
})
15+
}).listen(7999)

0 commit comments

Comments
 (0)