flatiron/director — Issue #81: Handling POST data
Author: icodejs
Created: 2012-02-20 01:38:41+00:00
State: open

Hi,

Maybe i am missing the point as to how the router should be used but could point me in the right direction?

What would be the best way to handle retrieving POST data from a form using Director?

I gather the code below doesn't work because: "The `this` context of the function passed to `.path()` is the Router itself."

I am using a basic form with method="post" and action="/save/"

router.path(/save/, function () {

this.post(function () {

var self = this;
var POST;

console.log('1: i got here');

self.res.writeHead(200, {'Content-type': 'text/html'});

self.req.on('data', function (chunk){

console.log('2: i got here');

POST = chunk;

}).on('end', function () {

console.log('3: i got here');

self.res.end(POST.toString());

});

});

});

The console prints '1: i got here', then the browser hangs waiting for an end response and nothing more is printed to the console.

I'd like to use the routing functionality rather than simply placing this code within router.dispatch function.

Any tips / pointers would be greatly appreciated.