node.js - Sails.js body contents when Content-Type is text/csv -
do need special handle post requests text-ish content-type?
i need handle text/csv when method in controller, looks sails.js tried parse body json:
poststuff: function(req, res) { sails.log.info("poststuff") sails.log.info(req.body) sails.log.info(req.headers['content-type']); ...etc... gives me:
info: poststuff info: {} info: text/csv i find documentation on bodyparser middleware little bit obscure.
fwiw, tried setting content-type text/plain in request, no avail.
i tried explicitly adding text bodyparser middleware, didn't seem have effect:
http.js
module.exports.http = { bodyparsertext: require('body-parser').text(), middleware: { order: [ 'startrequesttimer', 'cookieparser', 'session', 'myrequestlogger', 'bodyparser', 'bodyparsertext', 'handlebodyparsererror', 'compress', 'methodoverride', 'poweredby', '$custom', 'router', 'www', 'favicon', '404', '500' ], ...etc...
wow, turned out easy... annoyingly hard debug due lack of feedback framework.
in https.js, element new middleware had inside middleware element... if course makes sense:
module.exports.http = { // not here // bodyparsertext: require('body-parser').text(), middleware: { // here bodyparsertext: require('body-parser').text(), order: [ 'startrequesttimer', 'cookieparser', 'session', 'myrequestlogger', 'bodyparser', 'bodyparsertext', 'handlebodyparsererror', ...etc... would have been nice if sails.js (express?) gave warning, since i'm assuming couldn't find bodyparsertext.
Comments
Post a Comment