Jwan622
Jwan622

Reputation: 11649

Trying to make axios react request from localhost:8080 to a rails server localhost:3000

My rails server at localhost:3000 is serving this json:

enter image description here

and I'm trying to make a request from react like this:

import axios from 'axios'

export const ROOT_URL = 'localhost:3000';

export const FETCH_HANGOUTS = 'FETCH_HANGOUTS';

export function fetchHangouts() {
  const path = 'api/v1/hangouts'
  const url = `${ROOT_URL}/${path}`;
  const request = axios.get(url);
  console.log("url:", url)
  console.log("request:", request);

  return {
    type: FETCH_HANGOUTS,
    payload: request
  };
}

But this is failing with this error:

[[PromiseValue]]: Error: Network Error at createError (http://localhost:8080/bundle.js:23880:16) at XMLHttpRequest.handleError (http://localhost:8080/bundle.js:23732:15)`

What is going on?

Upvotes: 0

Views: 770

Answers (1)

Shahriat Hossain
Shahriat Hossain

Reputation: 340

The problem you are facing for CORS error. You can't access to your server because of cross origin policy as a result you are getting network error.

Upvotes: 1

Related Questions