但是公司的项目中还有包含文件的请求,此时body-paser就不能满足需求了,因此还是要重新使用sails默认的skipper,代码如下:
bodyParser: function() {
var xmlParser = require('express-xml-bodyparser')();
var skipper = require('skipper')();
return function(req, res, next) {
if (req.headers && (req.headers['content-type'] == 'text/xml' ||
req.headers['content-type'] == 'application/xml')) {
return xmlParser(req, res, next);
}
return skipper(req, res, next);
};
}
目前程序能够正常处理微信消息和常规请求,如果出现问题我会及时更新。