我正在尝试创建一个连接到 SQL Server 的 Azure 函数。响应没有被执行。我可以看到日志中返回的正确数据。关于在请求完成后如何让 context.res 返回的任何想法?
var rows = [];
module.exports = function (context, req, res) {
context.log('JavaScript HTTP trigger function processed a request.');
if(req.query.nfcID) {
connection.on('connect', function(err) {
request = new Request("select tagUID, ProductID, Active From Tags where TagUID = "+ req.query.nfcID,
function(err, rowCount, rows) {
if (err) {
context.log(err);
} else {
connection.close();
context.log('rows: '+rowCount);
}
});
request.on('row', function(columns) {
var row = {};
columns.forEach(function(column) {
row[column.metadata.colName] = column.value;
});
rows.push(row);
context.log(rows);
context.res = {
body: rows;
}
});
connection.execSql(request);
});
}
else {
context.res = {
status: 400,
body: "Please provide the nfc id"
};
}
context.done();
};