首页 > 解决方案 > 在本地调用 Firebase 云函数时,我收到 200 响应,但响应是 cors 类型响应,而不是我的实际数据

问题描述

Response {type: "cors", url: "Function url with params", 
redirected: false, status: 200, ok: true, …}
body: ReadableStream
bodyUsed: false
headers: Headers {}
ok: true
redirected: false
status: 200
statusText: ""
type: "cors"
url: "function url with params"
__proto__: Response

调用函数:

export function authDB(token,cb){
fetch(`${apiURL}auth?token=${token}`,{
    method:"GET"
    })
    .then(cb)
    .catch(error=>{
        console.log(error)
    })
}

我已在我的云功能中设置响应以允许 cors

response.set('Access-Control-Allow-Origin', "*")   
response.set('Access-Control-Allow-Methods', 'GET, POST')

使用 Postman 测试时,所有响应场景都是实际数据

标签: javascriptreactjsfirebasecors

解决方案


弄清楚了!我需要解析对 Json 的响应。

.then(res=>res.json())
.then(cb)

推荐阅读