javascript - 如何添加自定义 http header 以响应 Azure 函数

标签 javascript node.js http-headers azure-functions

我正在尝试使用来自客户端 javascript 应用程序的 google 身份验证的 azure 函数 (nodejs)。我已经为正确的 URL(即 http://localhost:8080)设置了 CORS。但我仍然收到以下错误:

Credentials flag is 'true', but the 'Access-Control-Allow-Credentials' header is ''. It must be 'true' to allow credentials. Origin 'http://localhost:8080' is therefore not allowed access.

我在互联网上到处尝试,并花了几天时间自己得到答案。似乎 Azure http 响应需要在 header 中添加此 Access-Control-Allow-Credentials:true 。有没有办法添加自定义 header ?

任何帮助将不胜感激。

最佳答案

在 Node 函数中,您可以指定额外的 header ,如下所示:

module.exports = function (context, req) {
    context.res = {
        status: 200,
        body: "Hello " + req.query.name,
        headers: {
            'Content-Type': 'text/plain',
            'MyCustomHeader': 'Testing'
        }
    };
    context.done();
}

关于javascript - 如何添加自定义 http header 以响应 Azure 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39215513/

相关文章:

javascript - 在 highcharts 中使用动态 html 渲染标题

javascript - jQuery 正则表达式测试

javascript - 使用 JavaScript 读取 html/body 标签 margin-top

javascript - 如何在 JavaScript 中将字符串转换为 bigInt

javascript - 解析 CSV 而不下载/保存

javascript - 在 anchor 标记中指定 HTTP header

javascript - 带有 style.display none 的 DIV 仍然出现

node.js - 如何使用sequelize通过外键值整齐地查询?

ruby - 你如何在 ruby​​ 中发送原始 header

linux - 在 curl 中拆分标题和内容