Azure Functions重定向头
我希望我的Azure功能之一执行 HTTP重定向.
I want one of my Azure Functions to do an HTTP Redirection.
这是该函数的当前代码:
This is the current code of the function:
module.exports = context => {
context.res.status(302)
context.res.header('Location', 'https://www.stackoverflow.com')
context.done()
}
但是它不起作用.
邮递员发送的请求显示响应如下:
A request sent from Postman shows the response has:
-
Status
:200 -
Location
未设置
-
Status
: 200 -
Location
not set
这是正确的代码吗?还是Azure Functions根本不允许这样做?
Is this correct code? Or is it simply not allowed by Azure Functions?
上面的代码确实有效,除非您将绑定名称设置为$ return,这就是我现在假定的名称(您可以检查集成标签)
The code above actually does work, unless you have your binding name set to $return, which is what I assume you have now (you can check in the integrate tab)
以下任一选项也可以满足您的需求
Either of the following options will also do what you're looking for
假定绑定配置中有$ return:
Assuming $return in the binding configuration:
module.exports = function (context, req) {
var res = { status: 302, headers: { "location": "https://www.stackoverflow.com" }, body: null};
context.done(null, res);
};
或使用表达风格" API(在绑定配置中不使用$ return):
Or using the "express style" API (not using $return in the binding configuration):
module.exports = function (context, req) {
context.res.status(302)
.set('location','https://www.stackoverflow.com')
.send();
};