jsheroes / community-help

Helping others is fun, ask away and the ClujJavaScripters community will help you!
15 stars 0 forks source link

CORS error while using axios in react-app #10

Closed robertistok closed 7 years ago

robertistok commented 7 years ago

Hello everybody!

I ran into this problem, while coding a react-redux app with nodejs, expressjs and mongodb. Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.

I google a lot, and also set my headers in the server, the code is pasted below: https://jsbin.com/gixemivici/edit?js

I observed this error, while sending a post request to the server via axios, this is the code for that: const request = axios({ method: 'post', url:${ROOT_URL}/signin, data: formValues, headers: [] });

I managed to workaround the problem using the "Allow-Control-Allow-Origin:*" google chrome extension, but I hope there is a nicer way :).

Thank you for your time reading my issue!

danburzo commented 7 years ago

You have a typo in Acces-Control-Allow-Headers, it should be Access-. That might be why Content-Type is not an accepted header.

robertistok commented 7 years ago

Ohh, I can't believe it, I'm a little bit ashamed.. Thank you very much, I must be more careful..

danburzo commented 7 years ago

Happens to all of us :)