【发布时间】:2015-02-06 13:24:05
【问题描述】:
我已经用繁琐的方式连接到 sql server 并为 restful api 进行了 restify 这是 server.js
server.get('/getInvoiceData', function (req, res, next) {
repository.GetInvoiceData(function(data){
res.send(data);
next();
});
});
invoice.js
exports.GetInvoiceData = function(callback){
var query = "SELECT * FROM [Snapdeal].[dbo].[tbl_Configuration]";
var req = new request(query,function(err,rowcount){
if (err)
{
console.log(err.toString());
}else{
console.log(rowcount+ " rows");
}
});
req.on('row',function(){
callback({customernumber:123});
});
connection.execSql(req);
}
我收到错误消息,因为发送后无法设置标头。
【问题讨论】:
-
您在
res.send(data)之后拨打了next()。调用send后,您已经发送了响应,因此无需调用next。 -
@RodrigoMedeiros 这是文档指定的执行方式。
标签: javascript node.js restify