-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-server.js
48 lines (41 loc) · 1.22 KB
/
test-server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import uWS from 'uWebSockets.js'
import rpc from '../lib/rpc'
const PORT = 9001;
let listenSocket;
exports.shutDownServer = () => {
console.log('server was shut down');
uWS.us_listen_socket_close(listenSocket)
listenSocket = null
}
exports.createServer = options => {
options = options || {}
options.port = options.port || PORT
if (typeof options !== 'object') {
throw new TypeError('options must be an object')
}
return uWS./*SSL*/App({
key_file_name: 'etc/ssl/key.pem',
cert_file_name: 'etc/ssl/cert.pem',
passphrase: 'Oxfords Not Brogues'
})
.ws('/*', {
/* Options */
compression: uWS.SHARED_COMPRESSOR,
maxPayloadLength: 16 * 1024 * 1024,
idleTimeout: 0,
/* Handlers */
open: ws => console.log('ws connected'),
message: rpc,
drain: ws => console.log(`ws backpressure: ${ws.getBufferedAmount()}`),
close: (ws, code, message) => console.log('ws closed')
})
.any('/*', (res, req) => res.end('nothing to see here'))
.listen(options.port, token => {
listenSocket = token
if (token) {
console.log('[arch|test|uws] listening to port:', options.port)
} else {
console.log('[arch|test|uws] failed to listen to port:', options.port)
}
})
}