I am having a problem with my isomorphic JavaScript application using React and Express.
I am trying to make an HTTP request using axios.get when my component mounts
componentDidMount() { const url = 'http://ufc-data-api.ufc.com/api/v3/iphone/fighters/title_holders'; axios.get(url).then( res => {
I get 200 res status from the API, but I don't get any response data and get an error message in my console
XMLHttpRequest cannot load http://ufc-data-api.ufc.com/api/v3/iphone/fighters/title_holders. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
However, if I make a request in my server.js
const url = 'http://ufc-data-api.ufc.com/api/v3/iphone/fighters/title_holders'; axios.get(url).then(res => {
It works fine, and I get response data when the server starts. Is this a problem with the actual API, or am I doing something wrong? If this is a CORS problem, I assume the request in server.js will not work either? Thanks!
Scott Davidson
source share