Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.server = http.createServer(async (req, res) => {
if (req.url !== ENDPOINT || !EventSource.isEventSource(req)) {
res.writeHead(404);
res.end();
return;
}
const client = new EventSource(req, res, DEFAULT_CLIENT_CONFIG);
this.clients.add(client);
debug('added reload connection', this.clients.size);
client.on('close', () => {
this.clients.delete(client);
debug('removed reload connection', this.clients.size);
});
});
router.get('/:script/events', function (req, res, next) {
if (!EventSource.isEventSource(req)) {
res.writeHead(400);
res.end();
return;
}
var source = new EventSource(req, res);
var bus = buses[req.params.script] || (buses[req.params.script] = createBus());
var watcher;
function onEvent(event) {
source.send(JSON.stringify(event), { event: event.type });
}
bus.addListener(onEvent);
source.on('close', function () {
bus.removeListener(onEvent);
watcher && watcher.close();
});
resolvePath(req.params.script)
.then(function (filename) {