Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (err) return fn(err);
response.writeHead(200, {
'Content-Length': data.length,
'Content-Type': 'text/javascript'
});
response.end(data);
});
// All other requests 404
} else {
response.writeHead(404);
response.end();
}
});
});
// Create socket server
self.wsServer = ws.attach(self.server);
self.wsServer.on('connection', function(socket) {
self._createConnection(socket);
});
fn();
});
};
app.get('/:key', function (req, res, next) {
var key = req.params.key;
if (connections[key]) {
res.render('remote', {
key: key
});
} else {
res.render('index', {
error: 'The key requested "' + key + '" is not being listened for. Fire up your client again.'
});
}
});
var server = ws.attach(app),
LISTEN = 1,
SERVE = 2;
server.on('connection', function (socket) {
var url = parse(socket.req.url);
var key = path.basename(url.pathname),
type = LISTEN;
if (url.pathname.indexOf('/listen/') === 0) {
if (!connections[key]) connections[key] = [];
connections[key].push(socket);
} else if (url.pathname.indexOf('/serve/') === 0) {
type = SERVE;
}
console.log((type == LISTEN ? 'listening: ' : 'serving: ') + key + ' - ' + (new Date));