Skip to content

Commit

Permalink
Send ready event
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonEtco committed Dec 7, 2017
1 parent 1a269ca commit 015ad53
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const bodyParser = require('body-parser')
const EventEmitter = require('events')
const path = require('path')

// Tiny logger to prevent logs in tests
const log = process.env.NODE_ENV === 'test' ? _ => _ : console.log

module.exports = () => {
const events = new EventEmitter()
const app = express()
Expand All @@ -31,6 +34,7 @@ module.exports = () => {
}, sse, (req, res) => {
// Allow CORS
res.setHeader('Access-Control-Allow-Origin', '*')
res.json({}, 'ready')

const channel = req.params.channel

Expand All @@ -39,10 +43,10 @@ module.exports = () => {

res.on('close', () => {
events.removeListener(channel, res.json)
console.log('Client disconnected', channel, events.listenerCount(channel))
log('Client disconnected', channel, events.listenerCount(channel))
})

console.log('Client connected', channel, events.listenerCount(channel))
log('Client connected', channel, events.listenerCount(channel))
})

app.post('/:channel', (req, res) => {
Expand Down

0 comments on commit 015ad53

Please sign in to comment.