javascript - 在本地调用 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 测试时,所有响应场景都是实际数据
解决方案
弄清楚了!我需要解析对 Json 的响应。
.then(res=>res.json())
.then(cb)
推荐阅读
- node.js - 使用 express 的 nodejs 中的 __dirname 变量出错
- r - 在不附加包的情况下获取惰性数据
- python - np.tensordot 用于点云的旋转?
- python - 使用 json 库/请求解析 JSON 文件
- javascript - 当用户到达页面末尾减去 x 像素量时加载页面
- reactjs - 如何修复未捕获的类型错误:调用函数时无法读取属性“props”?
- c++ - c ++代码块正常但仍然无法编译
- c++ - 为什么字符串和int之间的+运算符充当substr
- amazon-web-services - 用于 AWS S3 v4 身份验证问题的 Nginx 代理
- python - 如何将 Python 列表转换为 Python Dataframe?