Skip to content

Instantly share code, notes, and snippets.

@pherris

pherris/app.js

Created Mar 24, 2014
Embed
What would you like to do?
Node app for testing rule forward...
var express = require('express');
var app = express();
app.get('/', function(req, res){
var retryCount = req.query.retryCount;
console.log("req.query.retryCount: " + retryCount);
if (!retryCount || retryCount <3) {
res.send(500, 'retryCount under 3');
} else {
res.send('Hello World' + retryCount);
}
});
var server = app.listen(3000, function() {
console.log('Listening on port %d', server.address().port);
});
@chiappone

This comment has been minimized.

Copy link

@chiappone chiappone commented Mar 24, 2014

var express = require('express');
var app = express();
app.use (function(req, res, next) {
    var data='';
    req.setEncoding('utf8');
    req.on('data', function(chunk) {
      data += chunk;
    });

    req.on('end', function() {
        req.body = data;
        next();
    });
});

app.post('/', function(req, res)
{
    console.log(req.url);
    console.log(req.body);
    res.send(200, "");
});

console.log('listening for messages like POST localhost:3000/');
app.listen(3000);
@pherris

This comment has been minimized.

Copy link
Owner Author

@pherris pherris commented Mar 24, 2014

var express = require('express');
var app = express();

app.use (function(req, res, next) {
  var data='';
  req.setEncoding('utf8');
  req.on('data', function(chunk) {
    data += chunk;
  });

  req.on('end', function() {
    req.body = data;
    next();
  });
});

app.post('/', function(req, res){
  var retryCount = req.query.retryCount;
  console.log("req.query.retryCount: " + retryCount);
  console.log(req.body);
  if (!retryCount || retryCount <3) {
    console.log('500 returned');
    res.send(500, 'retryCount under 3');
  } else {
    console.log('200 returned');
    res.send('Hello World' + retryCount);
  }
});

var server = app.listen(3000, function() {
    console.log('Listening on port %d', server.address().port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment