我正在尝试使用来自客户端 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/