在Firebase中看不到请求标头的值? [英] Can't see value of request headers in firebase?

查看:49
本文介绍了在Firebase中看不到请求标头的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我执行以下操作:

var headers = new Headers();
headers.append("bunny", "test");
headers.append("rabbit", "jump");
fetch("blahurl.com/someservice", {headers:headers})

在火力基地上:

export const listener = functions.https.onRequest(async (req, res) => {
 for (let entry of req.rawHeaders) {
        console.log(entry); // here I see a 'bunny,rabbit' get printed somewhere
    }

     //However this yields undefined:
     req.headers.bunny

不确定如何获取标头值,我只有标头...

Not sure how to get the header values, I just have the headers...

推荐答案

问题似乎出在cors上,因此将函数的主体移入其中是可行的,就像这样:

Looks like the issue was with cors, so moving the body of the function into it worked, like so:

const cors = require('cors')({ origin: true });

export const listener = functions.https.onRequest(async (req, res) => {
    cors(req, res, () => {

然后cookie开始正确显示...

And then the cookies started appearing correctly...

我不确定为什么,这不是响应,而只是请求.

I'm not entirely sure why though, this isn't a response thing it's just a request.

这篇关于在Firebase中看不到请求标头的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆