-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
43 lines (34 loc) · 1.18 KB
/
app.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
#!/usr/bin/env node
const WebSocketServer = require('websocket').server;
const fs = require('fs');
const argv = require('./lib/arguments');
const httpServer = (argv.ssl) ? require('https') : require('http');
const controllers = require('./lib/connectionCtrl.js');
const utils = require('./lib/utils.js');
const PORT = argv.port;
if (!argv.password || !argv.ssl) console.log("\033[31m\nWARNING: It is recommended to set a password and use encrypted connections with sensible data.\n \x1b[0m")
function processReq(request, response) {
console.log((new Date()) + ' Received request for ' + request.url);
response.writeHead(404);
response.end();
}
let server;
if (argv.ssl) {
server = httpServer.createServer({
key: fs.readFileSync(argv.key, 'utf8'),
cert: fs.readFileSync(argv.cert, 'utf8'),
passphrase: argv.passphrase.toString()
}, processReq).listen(PORT);
} else {
server = httpServer.createServer(processReq).listen(PORT);
}
server.listen(PORT, () => {
utils.log('Server is listening on port ' + PORT);
});
wsServer = new WebSocketServer({
httpServer: server,
autoAcceptConnections: false
});
wsServer.on('request', request => {
controllers.onRequest(request, argv);
});