跨域请求被阻止,源“ null”无法访问

跨域请求被阻止,源“ null”无法访问

问题描述:

我正在一个项目中,我想通过Google API通过JS编写并使用React来获取日历事件。

I'm working on a project where I want to get my calendar events through google API, written in JS and using React.

我的问题是为什么我收到此错误?
我确实收到了日历事件,但是事先在网络浏览器的控制台中弹出了此错误,我已经在firefox&铬。

My question is why do I receive this error? I do receive my calendar events but beforehand this error pops up in the console of the web browser and I've tried it in firefox & chrome.

Chrome错误:
https:// gyazo.com/bf7687b094c24d0027bcbd4071783b8c

Chrome err: https://gyazo.com/bf7687b094c24d0027bcbd4071783b8c

Firefox错误:
https://gyazo.com/fa605bc75833d71070acbac34f1275da

Firefox err: https://gyazo.com/fa605bc75833d71070acbac34f1275da

这是我的app.js样子:
https://gyazo.com/f09b6906234c7d65b30ba4f40def1e50

This is how my app.js looks like: https://gyazo.com/f09b6906234c7d65b30ba4f40def1e50

某些服务器在预检OPTIONS请求中需要身份验证密钥。在cors附件下方添加以下行:

Some servers require auth key in the preflight OPTIONS request. Add the following line below your cors attachment:

app.use(cors());
app.options('*', cors());