Created
July 12, 2010 08:07
-
-
Save dunkfordyce/472239 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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