src/sandbox/events/index.js
function start(callback) {

  let {arc} = readArc()
  let close = x=> !x

  // if .arc has events and we're not clobbering with ARC_LOCAL flag
  if (arc.events || arc.queues) {
    // start a little web server
    let server = http.createServer(function listener(req, res) {
      let body = ''
      req.on('data', chunk => {
        body += chunk.toString()
      })
      req.on('end', () => {
        let message = JSON.parse(body)
        if (req.url === '/queues') {
          message.arcType = 'queue'
        } else if (req.url === '/events' || req.url === '/') {
          message.arcType = 'event'
        } else {
          res.statusCode = 404
          res.end('not found')
          console.log(chalk.red.dim('event bus 404 for URL ' + req.url))
          return
        }
        console.log(chalk.grey.dim('@' + message.arcType), chalk.green.dim(JSON.stringify(JSON.parse(body), null, 2)))
        // spawn a fork of the node process
        let subprocess = fork(path.join(__dirname, '_subprocess.js'))
        subprocess.send(message)
        subprocess.on('message', function _message(msg) {
          console.log(chalk.grey.dim(msg.text))
        })
        res.statusCode = 200
        res.end('ok')
      })
    })
    // ends our little web server
    close = function _closer() {
      try {
        server.close()
      }
      catch(e) {
        console.log('swallowing server.close error in sandbox events', e)
      }
    }
    // start listening on 3334
    server.listen(3334, callback ? callback: x=>!x)
  }
  else {
    callback()
  }
  return {close}
}
function start(callback) {

  let {arc} = readArc()
  let close = x=> !x

  // if .arc has events and we're not clobbering with ARC_LOCAL flag
  if (arc.events || arc.queues) {
    // start a little web server
    let server = http.createServer(function listener(req, res) {
      let body = ''
      req.on('data', chunk => {
        body += chunk.toString()
      })
      req.on('end', () => {
        let message = JSON.parse(body)
        if (req.url === '/queues') {
          message.arcType = 'queue'
        } else if (req.url === '/events' || req.url === '/') {
          message.arcType = 'event'
        } else {
          res.statusCode = 404
          res.end('not found')
          console.log(chalk.red.dim('event bus 404 for URL ' + req.url))
          return
        }
        console.log(chalk.grey.dim('@' + message.arcType), chalk.green.dim(JSON.stringify(JSON.parse(body), null, 2)))
        // spawn a fork of the node process
        let subprocess = fork(path.join(__dirname, '_subprocess.js'))
        subprocess.send(message)
        subprocess.on('message', function _message(msg) {
          console.log(chalk.grey.dim(msg.text))
        })
        res.statusCode = 200
        res.end('ok')
      })
    })
    // ends our little web server
    close = function _closer() {
      try {
        server.close()
      }
      catch(e) {
        console.log('swallowing server.close error in sandbox events', e)
      }
    }
    // start listening on 3334
    server.listen(3334, callback ? callback: x=>!x)
  }
  else {
    callback()
  }
  return {close}
}
function start ( callback ) { let { arc } = readArc ( ) let close = x => ! x // if .arc has events and we're not clobbering with ARC_LOCAL flag if ( arc . events || arc . queues ) { // start a little web server let server = http . createServer ( function listener ( req , res ) { let body = '' req . on ( 'data' , chunk => { body += chunk . toString ( ) } ) req . on ( 'end' , ( ) => { let message = JSON . parse ( body ) if ( req . url === '/queues' ) { message . arcType = 'queue' } else if ( req . url === '/events' || req . url === '/' ) { message . arcType = 'event' } else { res . statusCode = 404 res . end ( 'not found' ) console . log ( chalk . red . dim ( 'event bus 404 for URL ' + req . url ) ) return } console . log ( chalk . grey . dim ( '@' + message . arcType ) , chalk . green . dim ( JSON . stringify ( JSON . parse ( body ) , null , 2 ) ) ) // spawn a fork of the node process let subprocess = fork ( path . join ( __dirname , '_subprocess.js' ) ) subprocess . send ( message ) subprocess . on ( 'message' , function _message ( msg ) { console . log ( chalk . grey . dim ( msg . text ) ) } ) res . statusCode = 200 res . end ( 'ok' ) } ) } ) // ends our little web server close = function _closer ( ) { try { server . close ( ) } catch ( e ) { console . log ( 'swallowing server.close error in sandbox events' , e ) } } // start listening on 3334 server . listen ( 3334 , callback ? callback : x => ! x ) } else { callback ( ) } return { close } }
creates a little web server that listens for events on 3334
creates a little web server that listens for events on 3334