javascript - Azure Functions 重定向 header

标签 javascript azure azure-functions

我希望我的 Azure 函数之一执行 HTTP 重定向

这是该函数的当前代码:

module.exports = context => {
  context.res.status(302)
  context.res.header('Location', 'https://www.stackoverflow.com')
  context.done()
}

但是它不起作用。

从 Postman 发送的请求显示响应具有:

  • 状态:200
  • 位置未设置

这个代码正确吗?或者 Azure Functions 根本不允许这样做?

最佳答案

上面的代码实际上确实有效,除非您将绑定(bind)名称设置为 $return,这就是我假设您现在拥有的(您可以在集成选项卡中查看)

以下任一选项也可以满足您的要求

假设绑定(bind)配置中有$return:

module.exports = function (context, req) {
var res = { status: 302, headers: { "location": "https://www.stackoverflow.com" }, body: null};
context.done(null, res);
};

或者使用“express style”API(不在绑定(bind)配置中使用 $return):

module.exports = function (context, req) {
context.res.status(302)
            .set('location','https://www.stackoverflow.com')
            .send();
};

关于javascript - Azure Functions 重定向 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42931965/

相关文章:

Azure Functions 失败通知

azure - 需要 Blob 触发器 Azure Function 才能仅响应 BLOB UPLOAD

javascript - 为每行中的每个 td 添加唯一的类 jquery/coffeescript

javascript - Canvas 动画变慢

Javascript:更改id中的css子节点

powershell - 为 Azure 资源管理器模板部署 DSC 扩展时出现问题

java - java中的Azure应用程序功能用于查看azure存储帐户中的blob文件列表

javascript - 添加图像链接

azure - Rebus Azure ServiceBus - 源自外部服务的消息缺少 MessageID

c# - LINQ 运算符在泛型方法内部使用时不支持任何成员