-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
example.js
56 lines (49 loc) · 1.19 KB
/
example.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
49
50
51
52
53
54
55
56
'use strict'
var fs = require('fs')
var path = require('path')
var http = require('http')
var https = require('https')
var websocket = require('websocket-stream')
var net = require('net')
var tls = require('tls')
var aedes = require('aedes')
var logging = require('./')
var instance = aedes()
var servers = [
startHttp(),
startHttps(),
startNet(),
startTLS()
]
logging({
instance: instance,
servers: servers
})
function startHttp () {
var server = http.createServer()
websocket.createServer({
server: server
}, instance.handle)
server.listen(8880)
return server
}
function startHttps () {
var server = https.createServer({
key: fs.readFileSync(path.join(__dirname, 'certs', 'key.pem')),
cert: fs.readFileSync(path.join(__dirname, 'certs', 'cert.pem'))
})
websocket.createServer({
server: server
}, instance.handle)
server.listen(8881)
return server
}
function startNet () {
return net.createServer(instance.handle).listen(8882)
}
function startTLS () {
return tls.createServer({
key: fs.readFileSync(path.join(__dirname, 'certs', 'key.pem')),
cert: fs.readFileSync(path.join(__dirname, 'certs', 'cert.pem'))
}, instance.handle).listen(8883)
}