How to send axios request to Firebase from local hosting, CORS interferes now?
-
Good day! I'm currently taking one of the React courses 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 am using the default application start which is applied in react: react-scripts start. So I don't know where to insert the code related to node.js.
use this construction
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.
React Anonymous, Sep 8, 2019 -
In this case, the error was that the request link does not contain .json. The URL should look like this: https://quiz-react-3618f.firebaseio.com/quizes .jsonAnonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!