-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
36 lines (30 loc) · 1.03 KB
/
Copy pathmain.js
File metadata and controls
36 lines (30 loc) · 1.03 KB
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
const config = require('config')
const routeRegistrar = require('./lib/routeregistrar')
const streamRegistrar = require('./lib/streamregistrar')
const logger = require('./plugins/log')
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
logger('Error loading index.html')
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
let fs = require('fs')
let app = require('http').createServer(handler)
let io = require('socket.io')(app);
// Start the server on the specified port
let PORT = process.env.PORT || config.port || 3000
console.log(PORT)
app.listen(PORT);
// Listen to events on the specified namespace
let NAMESPACE = config.namespace || '/'
const nameSpace = io.of(NAMESPACE).on('connection', routeRegistrar)
module.exports.app = app
module.exports.socket = nameSpace
// Start consuming the streams
streamRegistrar()