-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (46 loc) · 1.49 KB
/
index.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
57
/*
* /app/index.js
*/
if (process.env.NODE_ENV === 'development') {
require('dotenv').config()
}
console.log('JSN:/index.js: NODE_ENV =', process.env.NODE_ENV);
const express = require("express");
const app = express();
//const compression = require('compression'),
const iface = '0.0.0.0';
const port = process.env.PORT || 3000;
let webserver = undefined;
if (true) {
//const http = require('http');
webserver = require('http').createServer(app);
}
else {
webserver = require('https').Server({
key: fs.readFileSync('/home/ubuntu/.letsencrypt/privkey.pem'),
cert: fs.readFileSync('/home/ubuntu/.letsencrypt/cert.pem'),
ca: fs.readFileSync('/home/ubuntu/.letsencrypt/chain.pem')
}, app);
}
//console.log('WEBServer =', webserver);
webserver.on('error', function(err) {
console.log('JSN:/index.js: WEBSERVER ERROR =', err);
});
var io = require('socket.io').listen(webserver);
//app.use(function(req, res, next) {
// res.io = io; // Turn on socket.io websocket server.
// next();
//});
io.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
//console.log('JSN:/index.js: client says =', data);
});
socket.on('jsn_request', function (data) {
console.log('JSN:/index.js:jsn_request: client says =', data);
});
});
webserver.listen(port, iface, () => {
console.log('JSN:/index.js: listening on interface: ' + iface + ' at port: ' + port + "\n");
});
require('./server/app.js')(app, express);