V
V
vasya0922020-11-20 16:28:03
React
vasya092, 2020-11-20 16:28:03

How to send an axios request to Firebase from local hosting, is CORS interfering now?

Good afternoon! Now I'm taking one of the courses on React and ran into one problem. The problem is that, due to CORS rules, I cannot access another domain from the local host.

There are many methods on the net, but many I do not know how to use in my case. I'm using the default application launch that is used in react: react-scripts start. So I don't know where to put the node.js related code.

I use this construct

try { 
  const response = await axios.post('https://quiz-react-3618f.firebaseio.com/quizes', this.state.quiz) 
  console.log(response) 
} catch(e) { 
  console.log(e); 
}


Error text:

Access to XMLHttpRequest at 'https://quiz-react-3618f.firebaseio.com/quiz' from origin 'https://quiz-react-3618f.web.app' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vasya092, 2020-11-20
@vasya092

In this case, the error was that the request link did not contain .json. The URL should look like this : https://quiz-react-3618f.firebaseio.com/quizes.json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question