Skip to content

Instantly share code, notes, and snippets.

@dunkfordyce
Created July 12, 2010 08:07
Show Gist options
  • Save dunkfordyce/472239 to your computer and use it in GitHub Desktop.
Save dunkfordyce/472239 to your computer and use it in GitHub Desktop.
var connect = require('connect'),
sys = require('sys');
if( 0 ) {
// this works
module.exports = connect.createServer(
function(req, resp) {
sys.puts('json request');
req.setEncoding('utf8');
var body = '';
req.addListener('data', function(data) {
sys.puts('data'+ data);
body += data;
});
req.addListener('end', function() {
sys.puts('done'+ body);
resp.writeHead(200, { 'Content-Type': 'text/plain' });
resp.end( "done" );
});
sys.puts('here');
}
);
} else {
// this doesnt execute the listeners
module.exports = connect.createServer(
connect.router(function(app) {
app.post('/posttest', function(req, resp, params) {
sys.puts('json request');
req.setEncoding('utf8');
var body = '';
req.addListener('data', function(data) {
sys.puts('data'+ data);
body += data;
});
req.addListener('end', function() {
sys.puts('done'+ body);
resp.writeHead(200, { 'Content-Type': 'text/plain' });
resp.end( "done" );
});
sys.puts('here');
});
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment