Azure Functions の NodeJS 関数を作成しています。ただし、context.res
呼び出し元に応答を返すために呼び出そうとすると、関数は次の例外で失敗します。
2016-06-26T07:45:59.171 Exception while executing function: Functions.getSASToken. mscorlib: TypeError: context.res is not a function
at module.exports (D:\home\site\wwwroot\getSASToken\index.js:63:26)
at eval (eval at <anonymous> (C:\Program Files (x86)\SiteExtensions\Functions\0.2.10238\bin\edge\double_edge.js:34:28), <anonymous>:42:7).
function.json
ファイルの内容:
{
"bindings": [
{
"webHookType": "",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"authLevel": "anonymous"
},
{
"name": "res",
"type": "http",
"direction": "out"
}
],
"disabled": false
}
そして問題の機能:
module.exports = function(context, req) {
var token = req.query.token;
var deviceId = req.query.deviceId;
var resourceUri = util.format('%s/devices/%s', sbNamespace, deviceId);
var sasToken = generateSasToken(resourceUri, token, null, 14400);
context.res({
status: 200,
body: sasToken
});
context.done();
}
context.bindings
オブジェクトを反復すると、プロパティのみが含まれていることがわかりますreq
(res
完全に欠落しています)。
参考までに、経由で応答オブジェクトをオーバーライドするとcontext.done(null, {res: {status:200, body: sasToken}}
、目的の出力が呼び出し元に返されます。