我正在开发一个应用程序,React + Redux
我的JSON
数据库在一个Firebase
数据库中。为此,我尝试fetch
从一个有效的 URL获取我的数据(从 Firebase 模拟器验证)
let firebase = 'https://******.firebaseio.com/**/*/***/*'
return (dispatch) => {
return fetch(firebase)
.then(res => res.json())
.then(json => dispatch({ type: 'GET_JSON', payload: json }))
}
这将返回给我错误:
Fetch API 无法加载https://console.firebase.google.com/project/****/database/data/**/*/***/*。从'https://console.firebase.google.com/project/重定向/数据库/数据/ ** / / / '到“https://accounts.google.com/ServiceLogin?ltmpl=firebase&osid=1&passive=true... ole.firebase.google.com/project/ /database/data/ / /** / ' 已被 CORS 策略阻止:请求的资源上不存在 'Access-Control-Allow-Origin' 标头。因此,不允许访问 Origin 'null'。如果不透明响应满足您的需求,请将请求的模式设置为“no-cors”以在禁用 CORS 的情况下获取资源。`
我尝试了很多解决方案,比如添加到 fetch 的第二个参数{ mode: 'no-cors', credentials: 'same-origin'}
,但是当我尝试这个时,我得到Uncaught (in promise) SyntaxError: Unexpected end of input
.
我错过了什么?