==========
var express = require('express'),
connect = require('connect');
var app = express.createServer(
);
app.configure(function() {
app.use(connect.methodOverride());
app.use(connect.bodyDecoder());
});
app.configure('development', function() {
app.use(connect.errorHandler({ dumpExceptions: true,
showStack: true }));
});
app.configure('production', function() {
app.use(connect.errorHandler());
});
app.get('/', function(req, res) {
res.send('hello! your params a and b = ' + req.param('a') + ',
' + req.param('b') + '\n');
});
app.post('/', function(req, res) {
res.send('hello! your params a and b = ' + req.param('a') + ',
' + req.param('b') + '\n');
});
app.listen(3000);
==============
Using curl to post always gives a 'hello! your params a and b =
undefined, undefined', whereas using it to 'get' always works. I have
done a dump, and the data is being sent correctly by curl (so no
problem there. Using curl to send to a sinatra app also works). I
believe bodyDecoder() should work for post params as well
(http://expressjs.com/guide.html#req-param-name-,
http://extjs.github.com/Connect/bodyDecoder.html), so... what gives?
-jf
--
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."
--Richard Stallman
"It's so hard to write a graphics driver that open-sourcing it would not help."
-- Andrew Fear, Software Product Manager, NVIDIA Corporation
http://kerneltrap.org/node/7228
-jf
First of all, proof that there's a problem:
$ curl 'localhost:3000/' -d 'a=postA&b=5'
hello! your params a and b = undefined, undefined
$ curl 'localhost:3000/?a=QUERYSTRING_A' -d 'a=POST_A&b=5'
hello! your params a and b = QUERYSTRING_A, undefined
selected lines from bodyDecoder.js:
=========
var queryString = require('querystring');
...
exports.decode = {
'application/x-www-form-urlencoded': queryString.parse,
'application/json': JSON.parse
};
...
// (this is the part where i get lost. Not that familiar with node.js yet!)
module.exports = function bodyDecoder(){
return function bodyDecoder(req, res, next) {
var decoder = exports.decode[mime(req)];
if (decoder) {
var data = '';
req.setEncoding('utf8');
req.addListener('data', function(chunk) { data += chunk; });
req.addListener('end', function() {
req.rawBody = data;
try {
req.body = data
? decoder(data)
: {};
} catch (err) {
return next(err);
}
next();
});
} else {
next();
}
}
};
=========
-jf
--
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."
--Richard Stallman
"It's so hard to write a graphics driver that open-sourcing it would not help."
-- Andrew Fear, Software Product Manager, NVIDIA Corporation
http://kerneltrap.org/node/7228
If I were to declare app as
var app = express.createServer(
connect.bodyDecoder()
);
, my problem is solved, and I can retrieve the post params...
Whereas if i were to do
var app = express.createServer(
);
app.configure(function() {
app.use(connect.bodyDecoder());
});
this would NOT work.
express -v = '1.0.0beta',
connect exports.version = '0.2.2'
--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.