var express = require('express'),
    http = require('http'),
    path = require('path'),
    amqp = require('amqp'),
    bodyParser = require('body-parser')

var status = {
  connection: 'No server connection',
  exchange: 'No exchange established',
  queue: 'No queue established'
}

var app = express()

app.set('port', process.env.PORT || 3000)

app.use(bodyParser.json())

app.post('/start-server', function(req, res){
  app.amqpConnection = amqp.createConnection({ host: 'localhost' })
  // Wait for connection to become established.
  app.amqpConnection.on('ready', function () {
    status.connection = 'Connection is ready';

    var options = {
      type: 'fanout',
      autoDelete: false
    }

    app.amqpConnection.exchange('logs', options, function(exchange){
      app.amqpExchange = exchange;
      status.exchange = 'Exchange is ready';
      res.send(status);
    });
  });
});

app.post('/emit-log', function(req, res){
  var newMessage = req.body;
  console.dir(newMessage);
  console.log('log message level: ' + newMessage.level + ' body: ' + newMessage.message);
  app.amqpExchange.publish('', newMessage.message);
  res.send('message sent');
});

http.createServer(app).listen(app.get('port'), function(){
  console.log('RabbitMQ + Node.js app is running on port ' + app.get('port') + '. To exit press CTRL+C');
});

@@ -379,52 +379,340 @@
 app.
-pos
+ge
 t('/sta
-rt-server', function(req, res)%7B%0A  
+tus', function(req, res)%7B%0A    res.send(status)%0A%7D)%0A%0Aapp.post('/emit-log', function(req, res)%7B%0A  var newMessage = req.body;%0A  console.dir(newMessage);%0A  console.log('log message level: ' + newMessage.level + ' body: ' + newMessage.message);%0A  app.amqpExchange.publish('', newMessage.message);%0A  res.send('message sent');%0A%7D)%0A%0A
 app.
@@ -773,18 +773,16 @@
 ost' %7D)%0A
-  
 // Wait 
@@ -819,18 +819,16 @@
 lished.%0A
-  
 app.amqp
@@ -866,18 +866,16 @@
  () %7B%0A  
- 
- 
 status.c
@@ -910,18 +910,16 @@
 eady';%0A%0A
-  
   var op
@@ -928,18 +928,16 @@
 ons = %7B%0A
-  
     type
@@ -952,18 +952,16 @@
 t',%0A    
-  
 autoDele
@@ -974,17 +974,50 @@
 lse%0A
-  
   %7D%0A%0A  
+// wait for exchange to be created%0A
   ap
@@ -1079,18 +1079,16 @@
 hange)%7B%0A
-  
     app.
@@ -1116,18 +1116,16 @@
 ge;%0A    
-  
 status.e
@@ -1161,320 +1161,13 @@
 ;%0A  
-    res.send(status);%0A    %7D);%0A  %7D);%0A%7D);%0A%0Aapp.post('/emit-log', function(req, res)%7B%0A  var newMessage = req.body;%0A  console.dir(newMessage);%0A  console.log('log message level: ' + newMessage.level + ' body: ' + newMessage.message);%0A  app.amqpExchange.publish('', newMessage.message);%0A  res.send('message sent');%0A%7D);
+%7D)%0A%7D)
 %0A%0Aht
@@ -1331,10 +1331,9 @@
 +C');%0A%7D)
-;
 %0A

update server to automatically connect to the queue